Exemple #1
0
        static void Main(string[] args)
        {
            var figureList = new FigureList();

            figureList.Add(new Circle(new Point(10, 20), 10));
            figureList.Add(new Rectangle(new Point(5, 15), 15, 25));
            figureList.Add(new Square(new Point(0, 0), 5));
            var points = new List <Point>
            {
                new Point(14, 26),
                new Point(23, 18),
                new Point(96, 21)
            };

            figureList.Add(new PolygonalChain(points));

            foreach (var figure in figureList)
            {
                figure.Draw();
            }

            var visitor = new JsonSerializerVisitor();

            visitor.Visit(new Circle(new Point(10, 20), 10));
            System.Console.WriteLine(visitor.Json);
        }
Exemple #2
0
        public FormMain()
        {
            InitializeComponent();
            formD       = new FormDialog();
            GpanelHolst = panelHolst.CreateGraphics();
            figlst      = new FigureList(GpanelHolst);

            lListOfBs = (from lAssembly in AppDomain.CurrentDomain.GetAssemblies()
                         from lType in lAssembly.GetTypes()
                         where typeof(Figure).IsAssignableFrom(lType)
                         select lType).ToList();

            foreach (Type j in lListOfBs)
            {
                if (j.Name != "Figure")
                {
                    figureToolStripMenuItem.DropDownItems.Add(j.Name);
                }
            }

            foreach (ToolStripMenuItem i in figureToolStripMenuItem.DropDownItems)
            {
                i.Click += new EventHandler(setCurrentFigure);
            }
        }
Exemple #3
0
 public Form1()
 {
     InitializeComponent();
     g = Graphics.FromHwnd(Handle);
     
     flist = new FigureList();
     ToolStripMenuItem item = new ToolStripMenuItem();
     TypeList = Assembly.GetExecutingAssembly().GetTypes().ToList().Where(t => t.Namespace == "kurs.Classes").ToList<Type>();
     for (int i = 0; i < TypeList.Count; i++)
     {
         if ((TypeList[i].Name != "Figure") && (TypeList[i].Name != "FigureList"))
         {
             item = new ToolStripMenuItem();
             item.Name = TypeList[i].Name;
             item.Text = TypeList[i].Name;
             ShapeToolStripMenuItem.DropDownItems.Add(item);
         }
     }
     CurrentInstrument = "Selection";
     labelCurrInstrument.Text = "Selection";
     textBox_Width.Text = "1";
     selectedIndex = selectionMode= -1;
     FillColor = Color.White;
     OutlineColor = Color.Black;
     needFilling = false;
     needOutline = true;
     tempX = tempY = panX = panY =0;
 }
Exemple #4
0
 public void Add(FigureList figures)
 {
     using (Transaction.Create(ActionManager, true))
     {
         figures.ForEach(Add);
     }
 }
        public void CheckRectangle()
        {
            var myList = new FigureList();
            var list   = new Do();

            list.MyList = myList;
            var rnd = new Random();

            for (int i = 0; i < 5; i++)
            {
                myList.Add(new Figure(2, i, i, i + 1, i + 1, rnd.Next(0, 8)), i); //+5 отреков с попарно разными
                myList.Add(new Figure(3, i, i, i, i, rnd.Next(0, 8)), i);         //+5 кругов
                myList.Add(new Figure(2, i, i, i, i, rnd.Next(0, 8)), i);         //+5 с одинаковыми XY координатами
            }
            var    newLine = list.LinesToRectangle();
            Figure item    = newLine.head;
            var    n       = -1;

            while (item != null)
            {
                if (item.Type == 2)
                {
                    n = 1;                //отрезков не осталось
                }
                item = item.Next;
            }
            Assert.AreEqual(-1, n);
        }
        public void CheckListByConst()//проверка метода создающего список из фигур площадь которых < конст
        {
            var myList = new FigureList();
            var list   = new Do();

            list.MyList = myList;
            var    newLine = list.BuildListByConst(10);
            Figure item    = newLine.head;
            var    n       = -1;

            while (item != null)
            {
                if (item.Type == 2)
                {
                    if ((item.XRD - item.XLU) * (item.YRD - item.YLU) < 10)
                    {
                        n = 1;
                    }
                }
                if (item.Type == 2)
                {
                    if (item.XRD * Math.PI * 2 < 10)
                    {
                        n = 1;
                    }
                }
                item = item.Next;
            }
            Assert.AreEqual(-1, n);
        }
        public void CheckEncode()//в файле 4 элемента было, проверял по длине, не додумался по-другому
        {
            var myList = new FigureList();
            var list   = new Do();

            list.MyList = myList;
            list.Encode();
            Assert.AreEqual(4, myList.Count());
        }
        public void CheckCorrectAdd()
        {
            var list = new FigureList();

            for (int i = 0; i < 4; i++)
            {
                list.Add(new Figure(1, 1, 1, 1, 1, 1), 0);
            }
            Assert.AreEqual(1, list.Count());
        }
Exemple #9
0
        private void openFileDialog_FileOk(object sender, CancelEventArgs e)
        {
            XmlSerializer reader = new XmlSerializer(typeof(FigureList));

            StreamReader file = new StreamReader(openFileDialog.FileName);

            figlst       = (FigureList)reader.Deserialize(file);
            figlst.holst = GpanelHolst;
            figlst.DrawList();
        }
Exemple #10
0
        public void openVHDLFile(string filename)
        {
            My_FileAnalyzer analyzer = new My_FileAnalyzer(filename, core);

            analyzer.Analyze();
            foreach (My_Figure fig in analyzer.figures)
            {
                FigureList.Add(fig);
            }
            Sort();
        }
Exemple #11
0
 public void SaveData(FigureList figureList, bool append = false)
 {
     using (StreamWriter writer = File.CreateText(PATH))
     {
         foreach (Shape obj in figureList.ObjectList)
         {
             string savedShape = XamlWriter.Save(obj);
             writer.WriteLine(savedShape);
         }
     }
 }
Exemple #12
0
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new Form1());

            var figure = new Figure();

            FigureControl.Ball = figure;
            FigureList.Add(FigureControl.Figure);
        }
        public void CheckRemove()
        {
            var myList = new FigureList();
            var rnd    = new Random();

            for (int i = 0; i < 7; i++)
            {
                myList.Add(new Figure(1, i, 0, 0, 0, 0), 0);
            }
            myList.Remove(new Figure(1, 0, 0, 0, 0, 0));
            Assert.AreEqual(6, myList.Count());
        }
Exemple #14
0
        public void HReverse(FigureList figures)
        {
            if (Figures.Any(f => f is Game.PBBall))
            {
                figures.ForEach(f => f.BallHReverse(GetBallPoint()));
            }
            else
            {
                figures.ForEach(f => f.HReverse());
            }

            Figures.UpdateVisual();
        }
Exemple #15
0
        public static PBLine CreateLine(Drawing drawing, FigureList dependencies, Webb.Playbook.Geometry.Game.PBRoutePoint pbPoint)
        {
            PBLine retLine = new PBLine()
            {
                Drawing     = drawing, Dependencies = dependencies,
                CapType     = pbPoint.CapType,
                LineType    = pbPoint.LineType,
                DashType    = pbPoint.DashType,
                StrokeColor = pbPoint.StrokeColor,
            };

            return(retLine);
        }
Exemple #16
0
 public void Add(FigureList figures, bool record)
 {
     if (record)
     {
         using (Transaction.Create(ActionManager, true))
         {
             figures.ForEach(Add);
         }
     }
     else
     {
         figures.ForEach(AddWithoutRecord);
     }
 }
Exemple #17
0
 private static IFigureList ReadDependencies(XElement figureNode, Dictionary<string, IFigure> dictionary)
 {
     FigureList result = new FigureList();
     foreach (var node in figureNode.Elements("Dependency"))
     {
         var name = node.ReadString("Name");
         IFigure figure = null;
         if (dictionary.TryGetValue(name, out figure))
         {
             result.Add(figure);
         }
     }
     return result;
 }
Exemple #18
0
        public static PBLine CreateLine(Drawing drawing, FigureList dependencies)
        {
            PBLine retLine = new PBLine()
            {
                Drawing      = drawing,
                Dependencies = dependencies,
            };

            if (Behavior.DrawVideo)
            {
                retLine.StrokeColor = Color;
            }

            return(retLine);
        }
 private void LoadToList()
 {
     for (int i = 0; i < FCoords.Count(); i++)
     {
         FigureList.SelectedIndexChanged += FigureList_SelectedIndexChanged;
         FigureList.Items.Add(i);
         FigureList.SelectedIndexChanged -= FigureList_SelectedIndexChanged;
     }
     if (coords.Count != 0)
     {
         FigureList.SelectedIndexChanged += FigureList_SelectedIndexChanged;
         FigureList.SetSelected(0, true);
         FigureList.SelectedIndexChanged -= FigureList_SelectedIndexChanged;
     }
 }
Exemple #20
0
        public void openVHDLFile(string filename, string EntityName)
        {
            if (System.IO.File.Exists(filename) == false)
            {
                return;
            }
            My_FileAnalyzer analyzer = new My_FileAnalyzer(filename, core);

            analyzer.Analyze(EntityName);
            info.Entity = analyzer.SelectedEntity;
            foreach (My_Figure fig in analyzer.figures)
            {
                FigureList.Add(fig);
            }
            Sort();
        }
        public void CheckDecode()
        {
            var myList = new FigureList();
            var list   = new Do();

            list.MyList = myList;
            var rnd = new Random();

            for (int i = 0; i < 7; i++)
            {
                myList.Add(new Figure(rnd.Next(1, 4), rnd.Next(0, 6), rnd.Next(0, 6),
                                      rnd.Next(0, 4), rnd.Next(0, 4), rnd.Next(0, 4)), i);
            }
            list.Decode();
            Assert.AreEqual(0, myList.Count());
        }
Exemple #22
0
 public Form1()
 {
     InitializeComponent();
     g = Graphics.FromHwnd(Handle);
     flist = new FigureList();
     TypeList = Assembly.GetExecutingAssembly().GetTypes().ToList().Where(t => t.Namespace == "lab1.Classes").ToList<Type>();
     for (int i = 0; i < TypeList.Count; i++)
     {
         if ((TypeList[i].Name != "Figure") && (TypeList[i].Name != "FigureList"))
         {
             ToolStripMenuItem item = new ToolStripMenuItem();
             item.Name = TypeList[i].Name;
             item.Text = TypeList[i].Name;
             shapeToolStripMenuItem.DropDownItems.Add(item);
         }
     }
 }
Exemple #23
0
        private void Init()
        {
            Bitmap     bmp     = new Bitmap(this.Width, this.Height);
            Graphics   graph   = Graphics.FromImage(bmp);
            FigureList Figures = new FigureList();

            Figures.Add(new Line(new Pen(Color.Red), 100, 100, 200, 200));
            Figures.Add(new Triangle(new Pen(Color.Blue), 250, 200, 300, 50, 350, 200));
            Figures.Add(new Rectangle(new Pen(Color.Black), 300, 300, 100, 200));
            Figures.Add(new Ellipse(new Pen(Color.Purple), 300, 300, 100, 200));
            Figures.Add(new Square(new Pen(Color.Green), 450, 300, 100));
            Figures.Add(new Circle(new Pen(Color.Brown), 450, 300, 100));
            for (int i = 0; i < Figures.Count; i++)
            {
                Figures[i].Draw(graph);
            }
            this.BackgroundImage = bmp;
        }
Exemple #24
0
        public FigureList GetOffFigures()
        {
            FigureList            offfigurelist = new FigureList();
            List <IFigure>        pathFigures;
            IEnumerable <IFigure> PbFigure = this.GetPBplayer();

            foreach (Game.PBPlayer pbplayer in PbFigure)
            {
                if (pbplayer.ScoutType == 0)
                {
                    pathFigures = pbplayer.GetPatheExceptEndPlayer(pbplayer, null, 0).ToList();
                    offfigurelist.Add(pbplayer as IFigure);
                    foreach (IFigure ifigure in pathFigures)
                    {
                        offfigurelist.Add(ifigure);
                    }
                }
            }
            return(offfigurelist);
        }
        public void CheckListByRectangleCoords()
        {
            var myList = new FigureList();
            var list   = new Do();

            list.MyList = myList;
            var    newLine = list.RectangleCoordinates(new Figure(1, 2, 3, 4, 5, 6));
            Figure item    = newLine.head;
            var    n       = -1;

            while (item != null)
            {
                if (item.XLU != 2 && item.YLU != 3) //проверка, есть ли фигуры с не такими параметрами
                {
                    n = 1;                          //100% общая точка - у отрезков: одинаковая точка,
                }
                item = item.Next;                   //а у круга одна точка и радиус меньше длины одной из сторон
            }
            Assert.AreEqual(-1, n);
        }
Exemple #26
0
        public void AddPassBlockArea(Geometry.Drawing drawing, Geometry.Game.PBPlayer player)
        {
            IEnumerable <IFigure> figures = player.GetPathPointFigure(player, null, 0);

            if (figures.Count() > 0)
            {// have path
                IFigure figure = player.GetEndFigure();

                if (figure is Game.PBPlayer)
                {
                    IEnumerable <IFigure> allFigures = player.GetPathFigure(player, null, 0);
                    IFigure lineFigure = allFigures.Last();
                    drawing.Remove(lineFigure);
                }
                player.ChangeLineType(CapType.BlockArea);
            }
            else
            {// no path
                player.ClearPath();

                IFigure    source       = player as IFigure;
                var        result       = Factory.CreateSubPoint(drawing, new Point(player.Coordinates.X, player.Coordinates.Y - 0.8));
                FigureList dependencies = new FigureList();
                dependencies.Add(source);
                dependencies.Add(result);
                PBLine         line             = Factory.CreateLine(drawing, dependencies);
                List <IFigure> figuresPassBlock = new List <IFigure>();
                figuresPassBlock.Add(line);
                figuresPassBlock.Add(result);
                drawing.Add(figuresPassBlock);
                if (!drawing.DrawingMode)
                {
                    line.CapType     = CapType.BlockArea;
                    line.StrokeColor = Webb.Playbook.Data.ColorSetting.Instance.BlockColor;
                }
                //player.Assignment = "Pass Block Area";
            }

            drawing.Figures.UpdateVisual();
        }
Exemple #27
0
        public static PBLine CreateArrowLine(Drawing drawing, FigureList dependencies)
        {
            PBLine retLine = new PBLine()
            {
                Drawing = drawing, Dependencies = dependencies, CapType = CapType.Arrow, LineType = LineType, DashType = DashType
            };

            if (drawing.DrawingMode)
            {
                retLine.CapType = CapType;

                retLine.StrokeColor = Color;

                retLine.StrokeThickness = StrokeThickness;
            }

            if (Behavior.DrawVideo)
            {
                retLine.StrokeColor = Color;
            }

            return(retLine);
        }
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            dataIO                = new DataIO(PATH);
            figureList            = new FigureList();
            figureList.ObjectList = new List <Shape>();
            try
            {
                figureList.ObjectList = dataIO.LoadData();
                if (!(figureList.ObjectList.Count == 0))
                {
                    foreach (Shape obj in figureList.ObjectList)
                    {
                        FigureField.Children.Add(obj);
                    }
                }

                RefreshPlugins();
                InitializeGUIComponents();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Exemple #29
0
        public FigureList GetOffPBPlayer()
        {
            FigureList            defpbplayer = new FigureList();
            IEnumerable <IFigure> PbFigure    = this.GetPBplayer();

            foreach (Game.PBPlayer pbplayer in PbFigure)
            {
                if (pbplayer.ScoutType == 0)
                {
                    defpbplayer.Add(pbplayer);
                }
            }
            Point point = new Point(0, 0);

            foreach (IFigure figure in Figures)
            {
                if (figure is Game.PBBall)
                {
                    defpbplayer.Add(figure);
                    break;
                }
            }
            return(defpbplayer);
        }
Exemple #30
0
 public FigureCreator()
 {
     FoundDependencies = new FigureList();
     ExpectedDependencies = InitExpectedDependencies();
 }
Exemple #31
0
 protected void InitFoundDependencies()
 {
     FoundDependencies = new FigureList();
 }
Exemple #32
0
        internal static PathGeometry InternalCombine(
            Geometry geometry1,
            Geometry geometry2,
            GeometryCombineMode mode,
            Transform transform,
            double tolerance,
            ToleranceType type)
        {
            PathGeometry resultGeometry = null;

            unsafe
            {
                MilMatrix3x2D matrix = CompositionResourceManager.TransformToMilMatrix3x2D(transform);

                PathGeometryData data1 = geometry1.GetPathGeometryData();
                PathGeometryData data2 = geometry2.GetPathGeometryData();

                fixed(byte *pPathData1 = data1.SerializedData)
                {
                    Debug.Assert(pPathData1 != (byte *)0);

                    fixed(byte *pPathData2 = data2.SerializedData)
                    {
                        Debug.Assert(pPathData2 != (byte *)0);

                        FillRule fillRule = FillRule.Nonzero;

                        FigureList list = new FigureList();
                        int        hr   = UnsafeNativeMethods.MilCoreApi.MilUtility_PathGeometryCombine(
                            &matrix,
                            &data1.Matrix,
                            data1.FillRule,
                            pPathData1,
                            data1.Size,
                            &data2.Matrix,
                            data2.FillRule,
                            pPathData2,
                            data2.Size,
                            tolerance,
                            type == ToleranceType.Relative,
                            new AddFigureToListDelegate(list.AddFigureToList),
                            mode,
                            out fillRule);

                        if (hr == (int)MILErrors.WGXERR_BADNUMBER)
                        {
                            // When we encounter NaNs in the renderer, we absorb the error and draw
                            // nothing. To be consistent, we return an empty geometry.
                            resultGeometry = new PathGeometry();
                        }
                        else
                        {
                            HRESULT.Check(hr);

                            resultGeometry = new PathGeometry(list.Figures, fillRule, null);
                        }
                    }
                }
            }

            return(resultGeometry);
        }
Exemple #33
0
 protected override void Reset()
 {
     base.Reset();
     FoundDependencies = new FigureList();
     RemoveTempPoint();
 }
Exemple #34
0
 private void openToolStripMenuItem_Click(object sender, EventArgs e)
 {
     List<Figure> list;
     flist = new FigureList();
     XmlSerializer formatter = new XmlSerializer(typeof(List<Figure>), TypeList.ToArray());
     openFileDialog1.InitialDirectory = "C:\tmp";
     openFileDialog1.Filter = "XML files (*.xml)|*.xml";
     if (openFileDialog1.ShowDialog() == DialogResult.OK)
     {
         try
         {
             using (FileStream fs = new FileStream(openFileDialog1.FileName, FileMode.OpenOrCreate))
                 list = (List<Figure>)formatter.Deserialize(fs);
         }
         catch (InvalidOperationException)
         {
             MessageBox.Show("Ошибка загрузки файла - отсутствуют требуемые классы");
             return;
         }
         foreach (Figure f in list)
         {
             flist.Add(f);
         }
         g.Clear(Color.White);
         Form1_Paint(this,null);
     }
 }
Exemple #35
0
 public void VReverse(FigureList figures)
 {
     figures.ForEach(f => f.VReverse());
     Figures.UpdateVisual();
 }
        internal static PathGeometry InternalCombine(
            Geometry geometry1,
            Geometry geometry2,
            GeometryCombineMode mode,
            Transform transform,
            double tolerance,
            ToleranceType type)
        {
            PathGeometry resultGeometry = null;

            unsafe
            {
                MilMatrix3x2D matrix = CompositionResourceManager.TransformToMilMatrix3x2D(transform);

                PathGeometryData data1 = geometry1.GetPathGeometryData();
                PathGeometryData data2 = geometry2.GetPathGeometryData();

                fixed (byte* pPathData1 = data1.SerializedData)
                {
                    Debug.Assert(pPathData1 != (byte*)0);

                    fixed (byte* pPathData2 = data2.SerializedData)
                    {
                        Debug.Assert(pPathData2 != (byte*)0);

                        FillRule fillRule = FillRule.Nonzero;

                        FigureList list = new FigureList();
                        int hr = UnsafeNativeMethods.MilCoreApi.MilUtility_PathGeometryCombine(
                            &matrix,
                            &data1.Matrix,
                            data1.FillRule,
                            pPathData1,
                            data1.Size,
                            &data2.Matrix,
                            data2.FillRule,
                            pPathData2,
                            data2.Size,
                            tolerance,
                            type == ToleranceType.Relative,
                            new AddFigureToListDelegate(list.AddFigureToList),
                            mode,
                            out fillRule);

                        if (hr == (int)MILErrors.WGXERR_BADNUMBER)
                        {
                            // When we encounter NaNs in the renderer, we absorb the error and draw
                            // nothing. To be consistent, we return an empty geometry.
                            resultGeometry = new PathGeometry();
                        }
                        else
                        {
                            HRESULT.Check(hr);

                            resultGeometry = new PathGeometry(list.Figures, fillRule, null);
                        }
                    }
                }
            }

            return resultGeometry;
        }
Exemple #37
0
 private void newToolStripMenuItem_Click(object sender, EventArgs e)
 {
     g = Graphics.FromHwnd(Handle);
     g.Clear(Color.White);
     flist = new FigureList();
 }