示例#1
0
        private void generateButton_Click(object sender, System.EventArgs e)
        {
            CancelRunningTask();
            var token = _tokenSource.Token;

            if (currentSize != (int)blockSizeBox.Value)
            {
                Task task = Task.Factory.StartNew(() =>
                {
                    blockSetGenerator = new IncrementalBlockSetGenerator((int)blockSizeBox.Value, token, new Random().Next());
                }, token).ContinueWith(_ => {
                    if (token.IsCancellationRequested)
                    {
                        return;
                    }
                    currentSize  = (int)blockSizeBox.Value;
                    board.Blocks = blockSetGenerator.GenerateBlocks((int)blockCountBox.Value);

                    var bitmap = BitmapGenerator.DrawBlockList(board.Blocks);

                    pictureBox.ClientSize = new Size(bitmap.Width, bitmap.Height);
                    pictureBox.Image      = bitmap;
                }, TaskScheduler.FromCurrentSynchronizationContext());
            }
            else
            {
                board.Blocks = blockSetGenerator.GenerateBlocks((int)blockCountBox.Value);

                var bitmap = BitmapGenerator.DrawBlockList(board.Blocks);

                pictureBox.ClientSize = new Size(bitmap.Width, bitmap.Height);
                pictureBox.Image      = bitmap;
            }
        }
        private void print_btn_Click(object sender, EventArgs e)
        {
            if (PrintingZednadebi)
            {
                List <string> detail_strings      = new List <string>();
                List <string> piece_count_strings = new List <string>();
                for (int i = 1; i <= 5; i++)
                {
                    detail_strings.Add(this.preview_area.Controls["ex" + i.ToString()].Text);
                }
                for (int j = 1; j <= 23; j++)
                {
                    piece_count_strings.Add(this.preview_area.Controls["ex_p" + j.ToString()].Text);
                }

                //C# assigns reference :|:|:|
                //reset image
                pages[0] = new Bitmap(pages[0].Width, pages[0].Height);
                Graphics origSurface = Graphics.FromImage(this.pages[0]);
                origSurface.DrawImage(this.OriginalPages[0], 0, 0);
                //
                pages[0] = BitmapGenerator.AddZedDetails(pages[0], detail_strings.ToArray());
                pages[0] = BitmapGenerator.AddZedCountTypes(pages[0], piece_count_strings.ToArray());
            }
            //
            if (DialogResult.OK == print_dlg.ShowDialog())
            {
                ChangePage(0);
                PrintInProgress           = true;
                print_doc.PrinterSettings = print_dlg.PrinterSettings;
                print_doc.Print();
            }
        }
示例#3
0
        private void button3_Click(object sender, EventArgs e)
        {
            var bmp = BitmapGenerator.GetBitmap(textBox1.Text, font, Rectangle.Empty, Color.Gray, Color.Transparent, format, System.Drawing.Text.TextRenderingHint.AntiAlias);

            GetBmpBox.Image = bmp;
            GetBmpBox.Size  = bmp.Size;
        }
示例#4
0
        private void heuristicRectangleButton_Click(object sender, System.EventArgs e)
        {
            CancelRunningTask();
            var token = _tokenSource.Token;

            if (board.Blocks == null)
            {
                return;
            }
            var watch = new System.Diagnostics.Stopwatch();
            Tuple <int[, ], int> result = new Tuple <int[, ], int>(new int[0, 0], 0);
            Task task = Task.Factory.StartNew(() =>
            {
                watch.Start();
                result = board.FastRectangle(token);
                watch.Stop();
            }, token).ContinueWith(_ => {
                if (token.IsCancellationRequested)
                {
                    return;
                }
                var bitmap = BitmapGenerator.DrawSolution(result.Item1);

                pictureBox.ClientSize = new Size(bitmap.Width, bitmap.Height);
                pictureBox.Image      = bitmap;
                labelInfo1.Text       = $"Time: {watch.ElapsedMilliseconds} ms";
                labelInfo2.Text       = $"Cuts: {result.Item2}";
            }, TaskScheduler.FromCurrentSynchronizationContext());
        }
示例#5
0
        private void optimalSquareButton_Click(object sender, System.EventArgs e)
        {
            CancelRunningTask();
            var token = _tokenSource.Token;

            if (board.Blocks == null)
            {
                return;
            }
            var watch = new System.Diagnostics.Stopwatch();

            int[,] result = new int[0, 0];
            Task task = Task.Factory.StartNew(() =>
            {
                watch.Start();
                result = board.Square(token);
                watch.Stop();
            }, token).ContinueWith(_ => {
                if (token.IsCancellationRequested)
                {
                    return;
                }
                var bitmap = BitmapGenerator.DrawSolution(result);

                pictureBox.ClientSize = new Size(bitmap.Width, bitmap.Height);
                pictureBox.Image      = bitmap;
                labelInfo1.Text       = $"Time: {watch.ElapsedMilliseconds} ms";
                labelInfo2.Text       = $"Square size: {result.GetLength(0)}x{result.GetLength(0)}";
            }, _tokenSource.Token, TaskContinuationOptions.None, TaskScheduler.FromCurrentSynchronizationContext());
        }
示例#6
0
        private void enable_this(object sender, System.EventArgs e)
        {
            this.Enabled = true;
            var bitmap = BitmapGenerator.DrawBlockList(board.Blocks);

            pictureBox.ClientSize = new Size(bitmap.Width, bitmap.Height);
            pictureBox.Image      = bitmap;
        }
示例#7
0
        private void Minefield_Handler(object sender, List <List <MinesweeperField> > e)
        {
            if (minefieldBitmap != null)
            {
                minefieldBitmap.Dispose();
            }

            minefieldBitmap   = BitmapGenerator.GenerateBitmap(e);
            pictureBox1.Size  = minefieldBitmap.Size;
            pictureBox1.Image = minefieldBitmap;
        }
示例#8
0
        private void deleteButton_Click(object sender, EventArgs e)
        {
            if (board.Blocks != null && board.Blocks.Count > 0)
            {
                this.board.Blocks.RemoveAt(board.Blocks.Count - 1);
                var bitmap = BitmapGenerator.DrawBlockList(board.Blocks);

                pictureBox.ClientSize = new Size(bitmap.Width, bitmap.Height);
                pictureBox.Image      = bitmap;
            }
        }
示例#9
0
        private void button2_Click(object sender, EventArgs e)
        {
            StringFormat fffm = StringFormat.GenericDefault;

            fffm.Alignment = StringAlignment.Center;
            //var bmp = BitmapGenerator.DrawString(textBox1.Text, font, Rectangle.Empty, 0, 0, Color.Gray, Color.Transparent, System.Drawing.Text.TextRenderingHint.AntiAlias);
            var bmp = BitmapGenerator.DrawText(textBox1.Text, font, Rectangle.Empty, StringFormat.GenericDefault, 0, 0, new SolidBrush(Color.Gray), Color.Transparent, System.Drawing.Text.TextRenderingHint.AntiAlias);

            DrawstringBox.Image = bmp;
            DrawstringBox.Size  = bmp.Size;
        }
示例#10
0
        private void refresh()
        {
            StringFormat fffm = StringFormat.GenericDefault;

            fffm.Alignment = StringAlignment.Center;
            var bmp = BitmapGenerator.DrawText(textBox1.Text, font, Rectangle.Empty, StringFormat.GenericDefault, 0, 0, new SolidBrush(Color.Gray), Color.Transparent, System.Drawing.Text.TextRenderingHint.AntiAlias);

            DrawstringBox.Image = bmp;
            DrawstringBox.Size  = bmp.Size;
            bmp             = BitmapGenerator.GetBitmap(textBox1.Text, font, Rectangle.Empty, Color.Gray, Color.Transparent, format, System.Drawing.Text.TextRenderingHint.AntiAlias);
            GetBmpBox.Image = bmp;
            GetBmpBox.Size  = bmp.Size;
        }
示例#11
0
        public void TearDown()
        {
            var status     = TestContext.CurrentContext.Result.Outcome.Status;
            var categories = TestContext.CurrentContext.Test.Properties["Category"];

            if ((status == TestStatus.Failed || status == TestStatus.Inconclusive) && categories.Contains(LayoutTestCategory))
            {
                var sizes  = TestContext.CurrentContext.Test.Arguments.FirstOrDefault(a => a is Size[]) as Size[];
                var bitmap = BitmapGenerator.CreateBitmap(defaultCenter, defaultSize, sizes);
                var path   = Path.Combine(TestContext.CurrentContext.TestDirectory,
                                          $"{TestContext.CurrentContext.Test.MethodName} {TestContext.CurrentContext.Test.Name}");
                bitmap.Save($"{path}.png", ImageFormat.Png);
                TestContext.Out.Write($"Tag cloud visualization saved to file {path}.png");
            }
        }
示例#12
0
        private void aboutToolStripMenuItem_Click(object sender, EventArgs e)
        {
            var dlg = new AboutForm
            {
                Text               = "About " + Application.ProductName,
                Image              = BitmapGenerator.GenerateAboutBitmap(),
                ProductName        = Application.ProductName,
                CopyrightOwner     = Application.CompanyName,
                Email              = "*****@*****.**",
                Credits            = "Development Team:\n James Parsons",
                LicenceInfo        = "Licenced to: " + TimeLicence.LicenceOwner + "\n\n" + TimeLicence.Report,
                UseAssemblyVersion = true,
            };

            dlg.ShowDialog(this);
        }
示例#13
0
 private void Construct(string text, Color fcolor, Color bgcolor, float fontsize, string fontname, StringFormat format, FontStyle style, float linesp, float charsp)
 {
     this.text          = text;
     this.fontColor     = fcolor;
     this.bgColor       = bgcolor;
     this.FontSize      = fontsize;
     this.fontName      = fontname;
     this.format        = format;
     this.FontStyle     = style;
     this.LineSpacing   = linesp;
     this.CharSpacing   = charsp;
     this.Rect          = Rectangle.Empty;
     this.renderingHint = TextRenderingHint.AntiAlias;
     this.VerticalFont  = false;
     //this.font = new Font(this.fontName, this.FontSize, this.FontStyle);
     this.Drawer = txtobj =>
     {
         return(BitmapGenerator.DrawText(txtobj.text, txtobj.font, txtobj.Rect, txtobj.format, txtobj.LineSpacing,
                                         txtobj.CharSpacing, txtobj.Brush, txtobj.bgColor, txtobj.renderingHint));
     };
 }
示例#14
0
        public void DrawData(DataTable data_arg, bool landscape_arg)
        {
            DirectBMPPrinting = false;
            this.pages_data   = data_arg;
            this.pages        = BitmapGenerator.RenderDataTable(data_arg, landscape_arg, false);
            LandscapePrinting = landscape_arg;
            if (LandscapePrinting)
            {
                rb_landscape.Checked = true;
            }
            else
            {
                rb_portrait.Checked = true;
            }

            Graphics g = draw_area.CreateGraphics();//this.CreateGraphics();

            g.Clear(this.BackColor);
            pageOffset = 0;
            g.DrawImage(pages[pageOffset], 0, 0);//2, 30);
        }
示例#15
0
        private void SellFormSubmit()
        {
            if ("" == (cash_handled_txt.Text ?? "")
                | 0 >= ParseDecimal(cash_handled_txt.Text ?? "")
                | false == IsHandledCashEnough()
                )
            {
                MessageBox.Show("თანხა არ არის საკმარისი!");
                return;
            }
            //sell button is clicked, so any invalid fields will get a red background unless corrected
            sell_clicked = true;
            //
            List <Remainder> RemsToSell = new List <Remainder>();

            foreach (DataGridViewRow nextRow in sell_grid.Rows)
            {
                if (nextRow.IsNewRow)
                {
                    continue;
                }
                Remainder nextRem = new Remainder();

                nextRem.product_barcode = (nextRow.Cells[sell_barcode_col.Index].Value ?? "").ToString();
                nextRem.storehouse_id   = ActiveStoreID;
                nextRem.initial_pieces  = ParseDecimal((nextRow.Cells[sell_piece_count_col.Index].Value ?? 0.0m).ToString());
                nextRem.sell_price      = ParseDecimal((nextRow.Cells[sell_piece_price_col.Index].Value ?? 0.0m).ToString());

                RemsToSell.Add(nextRem);
            }

            //determine how much there is to pay for the SellOrder
            decimal SellOrderTotal = 0.0m;

            foreach (Remainder next_selling_rem in RemsToSell.ToArray())
            {
                SellOrderTotal += next_selling_rem.sell_price * next_selling_rem.initial_pieces;
            }

            //prepare selling information and sell
            SellOrder CurrentSellOrder = new SellOrder(DateTime.Now
                                                       , true
                                                       , DataProvider.PaymentType.Nagdi
                                                       , Buyer.xelze
                                                       , null
                                                       , RemsToSell.ToArray()
                                                       , null);
            //this variable will be initialized by the AddSellOrder call
            //add SellOrder to database
            //use new fast optimized method instead of AddSellOrderWithPayment
            info SellResult = DataConn.FastAddShopInfoSellOrderWithPayment(CurrentSellOrder, Buyer.xelze.saidentifikacio_kodi
                                                                           , SellOrderTotal
                                                                           , ActiveStoreID
                                                                           , ActiveCashBoxID
                                                                           , ActiveCashierID);

            //success (code 0 means success, code 501 - NotImplementedYet, in early versions 501 was initial value and if it wasn't modified, it meant error did not occur (only erros modified success message). silly, right. )
            if (501 == SellResult.errcode | 0 == SellResult.errcode)
            {
                //print POS check and open cash drawer
                BitmapGenerator.PrintPOSCheck(CurrentSellOrder, ParseDecimal(cash_handled_txt.Text), ParseDecimal(cash_change_txt.Text), AllProducts, sActiveCashierName);
                //TODO:Open Cash Drawer (probably from utilities.external)
                //pay automatically for the SellOrder
                //////////pay code moved to transactional AddSellOrderWithPayment
                //notify (selling result + ) how the payment transfer resulted
                //NotifyOnScreen("პროდუქტები გაყიდულია. ", NotificationSeverity.Success);
                //TODO: insert wait time? to give the user time to look at the first notification
                //
                OpenCashDrawer();
                //
                NotifyOnScreen("პროდუქტები გაყიდულია. " + SellResult.details
                               , (0 == SellResult.errcode) ? NotificationSeverity.Success : NotificationSeverity.Error);

                //clear the list so next SellOrder can be entered
                sell_grid.Rows.Clear();
                //
                sell_grid.Focus();
                //
                cash_handled_txt.Text = "0.0";
                cash_change_txt.Text  = "0.0";
                //the sell button is not clicked yet for the next entered SellOrder, so we set it to false
                sell_clicked = false;

                //TODO: reset the per-row sum cache
                //nothing to do here. the real TODO is, when needed, to use the List<decimal> template instead of decimal[]
                Sell_Row_Pricing.Clear();
                //update total entered SellOrder sum (0.0 in this case, as no items have been entered yet)
                UpdateSumSellPrice();
                //
                //end success case
            }
            else if (404 == SellResult.errcode)
            {
                NotifyOnScreen("ამ რაოდენობის პროდუქტები საწყობში აღარაა დარჩენილი! ", NotificationSeverity.Error);
            }
            else
            {
                NotifyOnScreen("მოხდა შეცდომა. პროდუქტები არ გაყიდულა! ", NotificationSeverity.Error);
            }
            //
        }
示例#16
0
文件: Sensor.cs 项目: skpdvdd/NITEVis
        public Sensor(string config)
        {
            if (string.IsNullOrEmpty(config))
                throw new ArgumentNullException();

            try
            {
                _context = Context.CreateFromXmlFile(config, out _scriptNode);
                _depthGenerator = _context.FindExistingNode(NodeType.Depth) as DepthGenerator;
                _imageGenerator = _context.FindExistingNode(NodeType.Image) as ImageGenerator;
                _userGenerator = _context.FindExistingNode(NodeType.User) as UserGenerator;

                if (_depthGenerator == null)
                    throw new ApplicationException("No depth node found.");

                if (_imageGenerator == null)
                    throw new ApplicationException("No image node found.");

                if (_userGenerator == null)
                    throw new ApplicationException("No user node found.");

                if (_depthGenerator.MapOutputMode.FPS != _imageGenerator.MapOutputMode.FPS)
                    throw new ApplicationException("Depth and image node must have common framerates.");

                if (_depthGenerator.MapOutputMode.XRes != _imageGenerator.MapOutputMode.XRes)
                    throw new ApplicationException("Depth and image node must have common horizontal resolutions.");

                if (_depthGenerator.MapOutputMode.YRes != _imageGenerator.MapOutputMode.YRes)
                    throw new ApplicationException("Depth and image node must have common vertical resolutions.");

                _depthMetaData = new DepthMetaData();
                _imageMetaData = new ImageMetaData();

                _imageWidth = _depthGenerator.MapOutputMode.XRes;
                _imageHeight = _depthGenerator.MapOutputMode.YRes;

                _userGenerator.NewUser += new EventHandler<NewUserEventArgs>(_userGenerator_NewUser);
                _userGenerator.LostUser += new EventHandler<UserLostEventArgs>(_userGenerator_LostUser);
                _userGenerator.StartGenerating();

                _bitmapGenerator = new BitmapGenerator(this);

                _readerWaitHandle = new AutoResetEvent(false);

                _readerThread = new Thread(delegate()
                {
                    try
                    {
                        while (_run)
                        {
                            if (_pause)
                                _readerWaitHandle.WaitOne();

                            _context.WaitAndUpdateAll();

                            _depthGenerator.GetMetaData(_depthMetaData);
                            _imageGenerator.GetMetaData(_imageMetaData);

                            if (_depthMetaData.XRes != _imageWidth || _imageMetaData.XRes != _imageWidth)
                                throw new ApplicationException("Image width must not change.");

                            if (_depthMetaData.YRes != _imageHeight || _imageMetaData.YRes != _imageHeight)
                                throw new ApplicationException("Image height must not change.");

                            if (GeneratorUpdate != null)
                                GeneratorUpdate(this, EventArgs.Empty);
                        }
                    }
                    catch (ThreadInterruptedException)
                    {
                        Console.WriteLine("Reader thread interrupted.");
                    }
                    catch (Exception e)
                    {
                        throw new ApplicationException("Error while processing sensor data.", e);
                    }
                }) { Name = "ONI Reader Thread" };
            }
            catch (Exception)
            {
                throw;
            }
        }
示例#17
0
        private void fromFileButton_Click(object sender, System.EventArgs e)
        {
            CancelRunningTask();
            var token = _tokenSource.Token;

            if (currentSize != (int)blockSizeBox.Value)
            {
                blockSetGenerator = new IncrementalBlockSetGenerator((int)blockSizeBox.Value, token, new Random().Next());
                currentSize       = (int)blockSizeBox.Value;
            }

            OpenFileDialog openFileDialog = new OpenFileDialog();
            DialogResult   result         = openFileDialog.ShowDialog(); // Show the dialog.

            if (result != DialogResult.OK)
            {
                return;
            }
            string file = openFileDialog.FileName;

            try
            {
                var lines = File.ReadAllLines(file);
                for (int i = 0; i < lines.Length;)
                {
                    List <Block> blocks = new List <Block>();
                    if (!int.TryParse(lines[i], out int size))
                    {
                        return;
                    }
                    string alg     = lines[i + 1];
                    string input   = lines[i + 2];
                    var    numbers = input.Split(' ');
                    if (numbers.Length == 1)
                    {
                        if (!int.TryParse(input, out int count))
                        {
                            return;
                        }
                        blocks = new IncrementalBlockSetGenerator(size, token, new Random().Next()).GenerateBlocks(count);
                    }
                    else
                    {
                        switch (size)
                        {
                        case 5:
                            for (var index = 0; index < numbers.Length; index++)
                            {
                                var num = numbers[index];
                                if (!int.TryParse(num, out int count))
                                {
                                    return;
                                }
                                for (int j = 0; j < count; j++)
                                {
                                    blocks.Add(new PredefinedBlockSet(5).Get(index));
                                }
                            }
                            break;

                        case 6:
                            for (var index = 0; index < numbers.Length; index++)
                            {
                                var num = numbers[index];
                                if (!int.TryParse(num, out int count))
                                {
                                    return;
                                }
                                for (int j = 0; j < count; j++)
                                {
                                    blocks.Add(new PredefinedBlockSet(6).Get(index));
                                }
                            }
                            break;

                        default:
                            return;
                        }
                    }
                    board.Blocks = blocks;
                    break;
                }

                var bitmap = BitmapGenerator.DrawBlockList(board.Blocks);

                pictureBox.ClientSize = new Size(bitmap.Width, bitmap.Height);
                pictureBox.Image      = bitmap;
            }
            catch (IOException) { }
        }