Exemple #1
0
        /// <summary>
        /// Connect to the real plotter hardware
        /// </summary>
        private async void ButtonConnect_Click(object sender, RoutedEventArgs e)
        {
            this.ButtonConnect.IsEnabled = false;
            if (this.plotterRealHardware == null)
            {
                // set up plotter hardware
                var comportName = this.ComPortInput.Text;
                if (string.IsNullOrWhiteSpace(comportName))
                {
                    MessageBox.Show("No COM port name entered!");
                    this.ButtonConnect.IsEnabled = true;
                    return;
                }
                var hardware = new SovolS01Plotter(comportName);
                var result   = await hardware.GetReady();

                if (result.Success == false)
                {
                    MessageBox.Show($"Error set up plotter on port '{comportName}':{result.ErrorMessage}");
                    this.ButtonConnect.IsEnabled = true;
                    return;
                }
                this.plotterRealHardware    = hardware;
                this.ManualMover.Plotter    = hardware;
                this.ComPortInput.IsEnabled = false; // can't change com port after init
                this.PositionBox.IsEnabled  = true;
                this.ButtonPlot.IsEnabled   = true;
            }
        }
Exemple #2
0
 public override void Paint(IPlotter plotter, Position position)
 {
     foreach (var p in Paintables)
     {
         p.Paint(plotter, Positions[p].Translate(position));
     }
 }
Exemple #3
0
        public override bool Set(IPlotter plotter)
        {
            var webPlotter = plotter as CanvasPlotter;

            webPlotter.Context.Add(webPlotter.scriptBld.SetSolidColorFill(Color));
            return(true);
        }
Exemple #4
0
        public void Solve(IPlotter plotter)
        {
            // Given a magnitude N
            // Place N queens in a NxN chess board
            // in such a way that no queens attack each other

            const int size  = 8;
            var       board = _strategy.Solve(size);

            plotter.Plot(" ");
            for (var file = 1; file <= board.Size; file++)
            {
                plotter.Plot(" ");
                plotter.Plot(file.ToString());
            }
            plotter.PlotLine("");
            for (var rank = 1; rank <= board.Size; rank++)
            {
                plotter.Plot(rank.ToString());
                for (var file = 1; file <= board.Size; file++)
                {
                    plotter.Plot(" ");
                    plotter.Plot(board[rank, file].HasQueen ? "Q" : "-");
                }
                plotter.PlotLine("");
            }
        }
        public void Solve(IPlotter plotter)
        {
            // Given an array of N items, where each item is represented by a tuple (weight, value)
            // Given a knapsack weight capacity
            // Find the maximum total value in the knapsack without exceeding its capacity
            // Items cannot be fractioned

            ReadOnlySpan <Item> items = stackalloc Item[]
            {
                new Item {
                    Weight = 1, Value = 1
                },
                new Item {
                    Weight = 2, Value = 6
                },
                new Item {
                    Weight = 3, Value = 10
                },
                new Item {
                    Weight = 5, Value = 16
                }
            };

            var capacity = 7;

            var solution = _strategy.Solve(items, capacity);

            plotter.PlotValues(nameof(items), items);
            plotter.PlotValue(nameof(capacity), capacity);
            plotter.PlotValues(nameof(solution), (ReadOnlySpan <Item>)solution);
            plotter.PlotValue("total", solution.Sum(i => i.Value));
        }
    }
Exemple #6
0
        public override bool exec(IPlotter plotter)
        {
            var pl = plotter as mko.Graphic.WebClient.CanvasPlotter;

            pl.Context.Add(pl.scriptBld.restore());
            return(true);
        }
Exemple #7
0
        public override bool Set(IPlotter plotter)
        {
            var webPlotter = plotter as CanvasPlotter;

            webPlotter.Context.Add(webPlotter.scriptBld.SetSolidStrokeStyle(Color, Width));
            return(true);
        }
Exemple #8
0
 public void Init()
 {
     plotter = new Plotter {
         Position = new Coordinate {
             x = 0, y = 1
         }
     };
 }
 /// <summary>
 /// Get a data plotter for the specified fileid.
 /// </summary>
 /// <param name="savePath">The fileid to store the image at.</param>
 /// <returns>The plotter.</returns>
 private IPlotter GetPlotter(string savePath)
 {
     if (plotter == null)
     {
         plotter = new Plotter(savePath, "png", ImageFormat.Png);
     }
     return plotter;
 }
Exemple #10
0
 public Mapper(IPlotter plotter)
 {
     if (plotter == null)
     {
         throw new ArgumentNullException(nameof(plotter));
     }
     _plotter = plotter;
 }
Exemple #11
0
 public static void PlotValues <T>(this IPlotter plotter, string name, ReadOnlySpan <T> values)
 {
     plotter.PlotLine($"{name}:");
     for (var i = 0; i < values.Length; i++)
     {
         plotter.PlotValue($"  {i}", values[i]);
     }
 }
Exemple #12
0
 /// <summary>
 /// Get a data plotter for the specified fileid.
 /// </summary>
 /// <param name="savePath">The fileid to store the image at.</param>
 /// <returns>The plotter.</returns>
 private IPlotter GetPlotter(string savePath)
 {
     if (plotter == null)
     {
         plotter = new Plotter(savePath, "png", ImageFormat.Png);
     }
     return(plotter);
 }
Exemple #13
0
 public virtual void Paint(IPlotter plotter, Position position)
 {
     plotter.SetColor(new Color(255, 255, 255, 255), 2);
     plotter.FillRectangle(position, Size);
     plotter.SetColor(new Color(255, 0, 0, 255), 2);
     plotter.DrawRectangle(position, Size);
     plotter.DrawLine(position, new Position(position.X + Size.Width, position.Y + Size.Height));
     plotter.DrawLine(new Position(position.X + Size.Width, position.Y), new Position(position.X, position.Y + Size.Height));
 }
Exemple #14
0
 public async Task Show(IPlotter plotter)
 {
     try
     {
         await this.Plot.Show(plotter);
     }
     catch (Exception e)
     {
         Console.WriteLine(e);
         throw;
     }
 }
Exemple #15
0
 public async Task Show(IPlotter plotter)
 {
     try
     {
         await Show(plotter.ShowAsHtml());
     }
     catch (Exception e)
     {
         Console.WriteLine(e);
         throw;
     }
 }
Exemple #16
0
        public void Solve(IPlotter plotter)
        {
            // Given an array of numbers that represent the values of each coin
            // Given an amount
            // Find the minimum number of coins that are needed to make that amount

            ReadOnlySpan <int> coins = stackalloc int[] { 1, 5, 10, 25, 50 };
            const int          value = 74;

            var solution = _strategy.Solve(coins, value);

            plotter.PlotValue(nameof(value), value);
            for (var i = 0; i < coins.Length; i++)
            {
                plotter.PlotLine($"{solution[i]} coin(s) of {coins[i]}");
            }
        }
    }
Exemple #17
0
        public override bool draw(IPlotter plotter)
        {
            using (var path = plotter.BeginPath(Brush, Pen))
            {
                path.moveTo(P1);
                path.lineTo(P2);

                if (Outline)
                {
                    path.stroke();
                }
                if (Fill)
                {
                    path.fill();
                }

                return(true);
            }
        }
Exemple #18
0
        /// <summary>
        /// Plots and draws the sealing slabs.
        /// </summary>
        /// <param name="plotter">The plotter.</param>
        /// <param name="drawer">The drawer.</param>
        /// <param name="calculation">The calculation.</param>
        /// <param name="iteration">The iteration.</param>
        /// <param name="freeToTotalPixelRatioPercent">The free to total pixel ratio percent.</param>
        /// <param name="sealingSlabs">The sealing slabs.</param>
        private void PlotAndDraw(IPlotter plotter, BitBresenhamDrawer drawer, Calculation calculation, int iteration, out double freeToTotalPixelRatioPercent, out List <SealingSlab> sealingSlabs)
        {
            // Instantiate for each loop instead of initially, otherwise the memory will be exhausted.
            var grid = new BitGrid(calculation.WidthPixels, calculation.HeightPixels);

            sealingSlabs = plotter.PlotSealingSlabs <SealingSlab>().ToList();

            // Only save sealing slabs that were drawn.
            sealingSlabs = calculationService.DrawSealingSlabs(drawer, grid, sealingSlabs);

            foreach (var sealingSlab in sealingSlabs)
            {
                sealingSlab.CalculationId = calculation.Id;
                sealingSlab.Iteration     = iteration + 1;
            }

            // Save in percent.
            freeToTotalPixelRatioPercent = grid.FreeToTotalPixelRatioPercent;
        }
Exemple #19
0
        public static async Task Show(IPlotter plotter)
        {
            var thread = new Thread(() =>
            {
                try
                {
                    var window = new MainWindow();
                    window.Show(plotter);
                    window.ShowDialog();
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                    throw;
                }
            });

            thread.SetApartmentState(ApartmentState.STA);
            thread.Start();
        }
Exemple #20
0
        public static void Show(IPlotter plotter)
        {
            var thread = new Thread(() =>
            {
                try
                {
                    var window = new MainForm();
                    Application.Run(new MainForm());
                    window.ShowPlot(plotter);
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                    throw;
                }
            });

            thread.SetApartmentState(ApartmentState.STA);
            thread.Start();
        }
Exemple #21
0
        /// <summary>
        /// Gets the estimated seconds.
        /// </summary>
        /// <param name="plotter">The plotter.</param>
        /// <param name="calculation">The calculation.</param>
        /// <param name="circleChunkSize">Size of the circle chunk.</param>
        /// <returns></returns>
        private double GetEstimatedSeconds(IPlotter plotter, Calculation calculation, int circleChunkSize)
        {
            // Plot one iteration to have an estimation of sealing slab count
            double             freeToTotalPixelRatioPercent;
            List <SealingSlab> sealingSlabs;
            var drawer = new BitBresenhamDrawer();

            PlotAndDraw(plotter, drawer, calculation, 1, out freeToTotalPixelRatioPercent, out sealingSlabs);
            int sealingSlabCount = sealingSlabs.Count();

            int averageSealingSlabCount = sealingSlabCount * calculation.Iterations;

            // Not all iterations sealing slabs have to be saved and some may have already been saved.
            int maxIteration         = sealingSlabDepot.GetMaxIteration(calculation.Id);
            int saveSealingSlabCount = sealingSlabCount * (App.Config.SaveIterationsCount - maxIteration);

            return(estimationService.CalculateEstimatedTimeInSeconds(calculation.SealingSlabRadiusPixels,
                                                                     averageSealingSlabCount,
                                                                     saveSealingSlabCount,
                                                                     circleChunkSize));
        }
Exemple #22
0
        /// <summary>
        /// Calculates the unset area.
        /// </summary>
        /// <param name="calculation">The calculation.</param>
        /// <param name="plotter">The plotter.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns></returns>
        private UnsetAreaResult CalculateUnsetArea(Calculation calculation, IPlotter plotter, CancellationToken cancellationToken)
        {
            var drawer = new BitBresenhamDrawer();

            double[] freeToTotalPixelRatios = new double[calculation.Iterations];
            var      iterationSealingSlabs  = new List <SealingSlab> [calculation.Iterations];

            Parallel.For(0, calculation.Iterations, (i) =>
            {
                cancellationToken.ThrowIfCancellationRequested();

                double freeToTotalPixelRatioPercent;
                List <SealingSlab> sealingSlabs;

                PlotAndDraw(plotter, drawer, calculation, i, out freeToTotalPixelRatioPercent, out sealingSlabs);

                freeToTotalPixelRatios[i] = freeToTotalPixelRatioPercent;
                iterationSealingSlabs[i]  = sealingSlabs;
            });

            return(new UnsetAreaResult(iterationSealingSlabs, freeToTotalPixelRatios));
        }
Exemple #23
0
        public GameRendering(Game game,
                             GameRenderingConfig config,
                             RendererControl renderControl,
                             IPlotter gridPlotter) : base(game)
        {
            this.gridPlotter        = gridPlotter ?? throw new ArgumentNullException(nameof(gridPlotter));
            this.config             = config ?? throw new ArgumentNullException(nameof(config));
            config.PropertyChanged += OnRenderingConfigPropertyChanged;

            RenderControl = renderControl ?? throw new ArgumentNullException(nameof(renderControl));
            RenderControl.PropertyChanged += OnRenderPropertyChanged;

            if (config.RenderType != renderControl.ActiveRenderType)
            {
                throw new ArgumentException("RenderConfig render type and renderControl render type must match.");
            }

            RotationSteps = 0;
            CenterPointInMapCoordinates = new MapCoordinate(0, 0);

            plotters = new List <IPlotOperation>();
        }
Exemple #24
0
        public bool draw(IPlotter plotter)
        {
            // Kontextkommandos ausführen (z.B. Transformationen einstellen
            if (_contextCommands.Count > 0 && _contextCommands.Select(cmd => cmd.exec(plotter)).Any(success => !success))
            {
                return(false);
            }

            // Alle Unterblöcke zeichnen
            if (_subBlocks.Count > 0 && _subBlocks.Select(b => b.draw(plotter)).Any(success => !success))
            {
                return(false);
            }

            // Alle Figuren zeichnen
            if (_Shapes.Count > 0 && _Shapes.Select(s => s.draw(plotter)).Any(success => !success))
            {
                return(false);
            }

            return(true);
        }
        public Plotter2d(PictureBox plot, double xExtent, double yExtent, IPlotter plotter)
        {
            double xmin = -xExtent / 2.0;
            double xmax = xExtent / 2.0;
            double ymin = -yExtent / 2.0;
            double ymax = yExtent / 2.0;

            _plot    = plot;
            _plotter = plotter;
            _origin  = new PointD(0.0, 0.0);
            _vr      = new ViewReckoner(
                _border, plot.Width - _border, plot.Height - _border, _border,
                xmin, xmax, ymin, ymax);
            _plot.BackColor = Color.White;
            _plot.Paint    += new PaintEventHandler(OnPaint);

            // create the axis
            _axes       = new Axes();
            _axes.XAxis = new Axis(xmin, xmax, _origin.X, _noOfTicks);
            _axes.YAxis = new Axis(ymin, ymax, _origin.Y, _noOfTicks);

            // rubber band
            _plot.MouseDown += new MouseEventHandler(OnMouseDown);
            _plot.MouseUp   += new MouseEventHandler(OnMouseUp);
            _plot.MouseMove += new MouseEventHandler(OnMouseMove);

            // create image planes
            _mainImage   = new ImagePlane(_plot);
            _bandImage   = new ImagePlane(_plot);
            _mapperImage = new ImagePlane(_plot);

            Point oc = _vr.VToC(_origin);

            //_mapper = new Grid(oc.X, oc.X + _vr.CXSize / 4, 4, oc.Y, oc.Y - _vr.CYSize / 4, 4);
            //_mapper = new Line(oc, new Point(oc.X + _vr.CXSize / 4, oc.Y - _vr.CYSize / 4));

            Replot();
        }
Exemple #26
0
 public void ShowPlot(IPlotter plotter)
 {
     Task.WaitAll(Show(plotter.ShowAsHtml()));
 }
Exemple #27
0
 public static void PlotValue <T>(this IPlotter plotter, string name, T value)
 {
     plotter.PlotLine($"{name}: {value}");
 }
Exemple #28
0
 public override bool exec(IPlotter plotter)
 {
     return(((mko.Graphic.WebClient.CanvasPlotter)plotter).SetTrafo(Trafo));
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="MovesController"/> class.
 /// </summary>
 public MovesController()
 {
     this.spaceProbeProxy = new SpaceProbeProxy();
     this.plotter         = new Plotter();
 }
Exemple #30
0
 public override bool exec(IPlotter plotter)
 {
     return(Pen.Set(plotter));
 }
Exemple #31
0
 /// <summary>
 /// Create a chart generator using the specified data plotter.
 /// </summary>
 /// <param name="plotter">The plotter that will render the chart.</param>
 public StatisticsChartGenerator(IPlotter plotter)
 {
     this.plotter = plotter;
 }
Exemple #32
0
 public abstract bool exec(IPlotter plotter);
 /// <summary>
 /// Initializes a new instance of the <see cref="MovesController"/> class.
 /// </summary>
 public MovesController()
 {
     this.plotter = new Plotter();
 }
 /// <summary>
 /// Create a chart generator using the specified data plotter.
 /// </summary>
 /// <param name="plotter">The plotter that will render the chart.</param>
 public StatisticsChartGenerator(IPlotter plotter)
 {
     this.plotter = plotter;
 }