Example #1
0
        /// <summary>
        /// Performs the mouse down event.
        /// If mouse is pressed on any <see cref="Shape"/> on <see cref="Canvas"/>, then set this
        /// <seealso cref="object"/> selected, otherwise, deselect all <see cref="Shape"/>s and
        /// forms a <see cref="SelectedArea"/>.
        /// </summary>
        /// <remarks>Also updates the position of <see cref="_currentMousePoint"/>.</remarks>
        /// <param name="sender">The <seealso cref="object"/> which triggers the event.</param>
        /// <param name="e">The <seealso cref="EventArgs"/> containing information of mouse.</param>
        /// <seealso cref="Mode.OnMouseDown"/>
        public override void OnMouseDown(object sender, MouseEventArgs e)
        {
            _mousePressedPoint = new Point(e.X, e.Y);
            _currentMousePoint = new Point(e.X, e.Y);
            Shape = GetPressedShape(_currentMousePoint);

            if (Shape != null)
            {
                if (!Shape.IsSelected)
                {
                    SingleSelect(Shape);
                }
            }
            else
            {
                //Mouse pressed on blank field: deselect all shapes
                DeselectAll();
                //Not a single shape selected: prepare to form a selection area.
                Shape = new SelectedArea(e.X, e.Y);
                Canvas.AddShape(Shape);
                _hasSelectArea = true;
            }

            base.OnMouseDown(sender, e);
        }
Example #2
0
 private void OnGUI()
 {
     if (isSelecting)
     {
         unitSelected.Clear();
         var rect = SelectedArea.GetScreenrect(mousePosition, Input.mousePosition);
         SelectedArea.DrawScreenRect(rect, new Color(0.8f, 0.8f, 0.95f, 0.25f));
         SelectedArea.DrawScreenRectBorder(rect, 2, new Color(0.8f, 0.8f, 0.95f, 0.25f));
         List <SoldierController> soldiers = GameController.instance.GetSoldiers();
         foreach (SoldierController soldier in soldiers)
         {
             Vector2 pos = new Vector2(Camera.main.WorldToScreenPoint(soldier.GetPositions()).x, Screen.height - Camera.main.WorldToScreenPoint(soldier.GetPositions()).y);
             if (rect.Contains(pos))
             {
                 if (unitSelected.Count == 0)
                 {
                     unitSelected.Add(soldier);
                 }
                 else if (!CheckUnit(soldier))
                 {
                     unitSelected.Add(soldier);
                 }
             }
         }
     }
 }
Example #3
0
        private string SerializeImageArea(Bitmap img, SelectedArea area)
        {
            var hiddenArea = GetArea(img, area);
            var bits       = hiddenArea.ToBitString();

            bits = area.X.ToBitString() + area.Y.ToBitString() + area.Width.ToBitString() + area.Height.ToBitString() + bits;
            return(bits);
        }
Example #4
0
 /// <summary>
 /// Initializes a new instance of the MainViewModel class.
 /// </summary>
 public ConcealmentViewModel()
 {
     OriginalImagePath       = @"Resources\Document.png";
     OpenOriginalImgCommand  = new RelayCommand(OpenOriginalImage);
     OpenProcessedImgCommand = new RelayCommand(OpenProcessedImage);
     HideCommand             = new RelayCommand(Hide, () => !string.IsNullOrEmpty(OriginalImagePath) && _selectedArea != null);
     ShowCommand             = new RelayCommand(Show, () => !string.IsNullOrEmpty(ProcessedImagePath));
     Messenger.Default.Register <AreaSelectedMessage>(this, msg => _selectedArea = msg.Area);
 }
Example #5
0
        public Bitmap HideArea(Bitmap img, SelectedArea area)
        {
            var serializedArea = SerializeImageArea(img, area);
            var encryptedBits  = _feistelEncoder.Encrypt(serializedArea.ToStringFromBinary(), Key);
            var image          = (Bitmap)img.Clone();

            using (var graphics = Graphics.FromImage(image))
            {
                graphics.FillRectangle(new SolidBrush(_hiddenAreaColor), area.X, area.Y, area.Width, area.Height);
            }
            return(_encoder.Encode(encryptedBits, image));
        }
        public Task <MathPixAPI> OcrSelectedArea()
        {
            if (SelectedArea != null && SelectedArea.Type == PDFAreaSelection.AreaType.Ocr)
            {
                if (string.IsNullOrWhiteSpace(Config.MathPixAppId) ||
                    string.IsNullOrWhiteSpace(Config.MathPixAppKey))
                {
                    MessageBox.Show("OCR unavailable. Please configure your AppId and AppKey.",
                                    "Error: Ocr");
                }

                else
                {
                    ShowLoadingIndicator();

                    var(lt, rb) = SelectedArea.NormalizedPoints();
                    var img = RenderArea(SelectedArea.PageIndex,
                                         lt,
                                         rb);

                    return(MathPixAPI.Ocr(Config.MathPixAppId,
                                          Config.MathPixAppKey,
                                          Config.MathPixMetadata,
                                          img)
                           .ContinueWith(
                               mathPixRes =>
                    {
                        try
                        {
                            var mathPix = mathPixRes.Result;

                            if (mathPix == null || string.IsNullOrWhiteSpace(mathPix.Error) == false)
                            {
                                MessageBox.Show($"Ocr failed. {mathPix?.Error}",
                                                "Error: Ocr");
                                SelectedArea = null;
                                return null;
                            }

                            return mathPix;
                        }
                        finally
                        {
                            Dispatcher.Invoke(HideLoadingIndicator);
                        }
                    }));
                }
            }

            return(null);
        }
Example #7
0
        public void SetAreaList()
        {
            if (!string.IsNullOrEmpty(this.ChannelID))
            {
                string key = string.Format("Area-{0}-{1}-NewsAdv", this.CompanyCode, this.ChannelID);
                CodeNamePairHelper.GetList("MKT", key, (s, args) =>
                {
                    if (args.FaultsHandle())
                    {
                        return;
                    }
                    List <CheckBoxVM> list = new List <CheckBoxVM>();
                    args.Result.ForEach(item =>
                    {
                        CheckBoxVM cbvm = new CheckBoxVM();
                        cbvm.Name       = item.Name;
                        cbvm.SysNo      = int.Parse(item.Code);

                        if (!string.IsNullOrEmpty(SelectedArea))
                        {
                            cbvm.IsChecked = SelectedArea.Split(',').Where(p => p.ToString() == item.Code).Count() > 0;
                        }

                        cbvm.onSelectedChange = new OnSelectedChange(SetSelectedArea);
                        list.Add(cbvm);
                    });

                    areaList.ItemsSource = list;

                    var handler = LoadAreaCompleted;
                    if (handler != null)
                    {
                        handler(this, args);
                    }
                });
            }
        }
Example #8
0
        /// <summary>
        /// Paints all the colors on the grid.
        /// </summary>
        /// <param name="g">Graphics object.</param>
        private void PaintGrid(Graphics g)
        {
            EstablishPalettes();

            var WorkingWidth = this.ClientRectangle.Width - Padding.Horizontal;

            var       GridArea           = new Rectangle(0, 0, _gridSize.Width, _gridSize.Height);
            var       EmbiggenedGridArea = new Rectangle(0, 0, _gridSize.Width + _gridPadding * 3, _gridSize.Height + _gridPadding * 3);
            var       GridOutline        = new Rectangle(0, 0, GridArea.Width - 1, GridArea.Height - 1);
            var       TextBounds         = new RectangleF(_gridSize.Width + _gridPadding * 2, _gridPadding, this.Width - (_gridSize.Width + _gridPadding * 3), _gridSize.Height);
            Rectangle SelectedArea;
            var       TextColor     = SystemColors.WindowText;
            var       Measure       = SizeF.Empty;
            var       IsSelected    = false;
            var       IsHotTracking = false;
            var       Name          = string.Empty;
            int       HalfPad       = _gridPadding / 2;
            int       DeltaX        = _gridPadding + _gridSize.Width;
            int       DeltaY        = _gridPadding + _gridSize.Height;
            int       MinX          = this.Padding.Left + _gridPadding;
            int       MinY          = this.Padding.Top + _gridPadding;
            int       X             = MinX;
            int       Y             = MinY;
            var       MaxX          = this.ClientRectangle.Width - Padding.Right - _gridPadding;
            var       BoldFont      = new Font(this.Font, FontStyle.Bold);

            if (_showNames)
            {
                EmbiggenedGridArea = new Rectangle(0, 0, _gridSize.Width + _gridPadding * 2, _gridSize.Height + _gridPadding * 2);
            }

            // Setup the StringFormat object
            var StringFormat = new StringFormat
            {
                Trimming = StringTrimming.EllipsisCharacter
            };

            using (var GridBrush = new SolidBrush(Color.Black))
            {
                using (var OutlinePen = new Pen(System.Drawing.SystemColors.ControlDarkDark))
                {
                    OutlinePen.Alignment = System.Drawing.Drawing2D.PenAlignment.Inset;
                    OutlinePen.Width     = 0.5f;

                    for (var i = 0; i < _combinedList.Count; i++)
                    {
                        if ((i == _customStartIndex) && (_customList.Count > 0))
                        {
                            if (X > MinX)
                            {
                                X  = MinX;
                                Y += DeltaY;
                            }
                            g.DrawLine(OutlinePen, X, Y, MaxX, Y);
                            Y += _gridPadding;
                        }

                        GridArea.Location    = new Point(X, Y);
                        GridOutline.Location = new Point(X, Y);
                        TextBounds.Y         = Y;

                        Name          = _combinedList[i].Name;
                        IsSelected    = (i == _selectedIndex);
                        IsHotTracking = (_hotTracking && (i == _hoverIndex));

                        if (_showNames)
                        {
                            SelectedArea = new Rectangle(0, GridArea.Top - HalfPad, this.Width, GridArea.Height + _gridPadding);
                        }
                        else
                        {
                            SelectedArea = GridArea;
                            SelectedArea.Inflate(1, 1);
                        }

                        if (IsSelected)
                        {
                            g.FillRectangle(SystemBrushes.Highlight, SelectedArea);
                            TextColor = SystemColors.HighlightText;
                        }

                        else if (IsHotTracking)
                        {
                            g.FillRectangle(SystemBrushes.HotTrack, SelectedArea);
                            TextColor = SystemColors.HighlightText;
                        }
                        else
                        {
                            TextColor = SystemColors.WindowText;
                        }

                        using (HatchBrush HatchBrush = new HatchBrush(HatchStyle.LargeCheckerBoard, Color.White, Color.Silver))
                            g.FillRectangle(HatchBrush, GridArea);

                        GridBrush.Color = _combinedList[i].Color;

                        // Paint the color
                        g.FillRectangle(GridBrush, GridArea);
                        _combinedList[i].Location = GridArea.Location;

                        // Draw the Name
                        if (_showNames)
                        {
                            Measure = g.MeasureString(Name, (IsSelected || IsHotTracking) ? BoldFont : this.Font);
                            TextBounds.Offset(0, (_gridSize.Height - Measure.Height) / 2f);
                            TextBounds.Height = Measure.Height;
                            using (SolidBrush TextBrush = new SolidBrush(TextColor))
                                g.DrawString(Name, ((IsSelected || IsHotTracking) ? BoldFont : this.Font), TextBrush, TextBounds, StringFormat);
                        }

                        // Border the color
                        g.DrawRectangle(OutlinePen, GridOutline);

                        // Move to the next position
                        if (!_showNames)
                        {
                            X += DeltaX;
                            //if ((X + DeltaX) > this.Size.Width)
                            if ((X + DeltaX) > MaxX)
                            {
                                //if (MaxX == 0)
                                //{
                                //    MaxX = X - DeltaX + _gridSize.Width;
                                //}

                                X  = MinX;
                                Y += DeltaY;
                            }
                        }
                        else
                        {
                            Y   += DeltaY;
                            MaxX = (int)TextBounds.Right;
                        }
                    }
                }
            }

            // If these buttons are present, increment the height and reposition these buttons at the bottom.
            //if ((_allowAddColors || _allowEmptyColor) && !_showNames)
            if (_allowAddColors || _allowEmptyColor)
            {
                if (X > MinX)
                {
                    X  = MinX;
                    Y += DeltaY;
                }
                if (_allowAddColors)
                {
                    cmdAddColor.Location = new Point(X, Y);
                    X += cmdAddColor.Width + _gridPadding;
                }
                if (_allowEmptyColor)
                {
                    cmdEmptyColor.Location = new Point(X, Y);
                }
                Y += Math.Max(cmdAddColor.Height, cmdEmptyColor.Height) + _gridPadding;
                Y += _gridPadding;
            }
            else
            {
                if (X > MinX)
                {
                    X  = MinX;
                    Y += DeltaY;
                }
            }

            if (_stretchToFitParent && (Y < (Parent.ClientRectangle.Height - Padding.Bottom)))
            {
                Y = Parent.ClientRectangle.Height - _gridPadding - this.Padding.Vertical;
            }
            this.Height = Y;

            if (_embiggenHotTracked && (_hoverIndex >= 0))
            {
                var eNamed = _combinedList[_hoverIndex];
                var Center = new Point(eNamed.Location.X + _gridSize.Width / 2, eNamed.Location.Y + _gridSize.Height / 2);
                EmbiggenedGridArea.Location = new Point(Center.X - EmbiggenedGridArea.Width / 2, Center.Y - EmbiggenedGridArea.Height / 2);
                using (var HatchBrush = new HatchBrush(HatchStyle.LargeCheckerBoard, Color.White, Color.Silver))
                    g.FillRectangle(HatchBrush, EmbiggenedGridArea);
                using (var GridBrush = new SolidBrush(eNamed.Color))
                    g.FillRectangle(GridBrush, EmbiggenedGridArea);
                using (var GridPen = new Pen(SystemColors.HotTrack, 2))
                    g.DrawRectangle(GridPen, EmbiggenedGridArea);
            }
        }
Example #9
0
        public void Save()
        {
            if (SelectedPatient != null && SelectedPatient.NewlyAdded)
            {
                PatientsList.Add(SelectedPatient);
                SelectedPatient.NewlyAdded = false;
            }
            try
            {
                bool   shouldDisplayMessage;
                double cost             = MaterialCost.HasValue ? MaterialCost.Value : 0;
                var    itemsNotSelected = GetNotAddedInformation(out shouldDisplayMessage);
                if (shouldDisplayMessage)
                {
                    MessageBox.Show("Inainte de a salva adaugati :" + itemsNotSelected);
                    return;
                }
                var duration = TimeSpan.FromMinutes(Convert.ToDouble(Durata));
                EndTIme = StartingHour.Add(duration);
                double percentage = SelectedPercentage != null
                    ? SelectedPercentage.Percentage / 100
                    : (SelectedWork != null && SelectedWork.Percent != 0 ? SelectedWork.Percent / 100 : 1);

                var intervention = new LocalIntervention()
                {
                    Id       = Id,
                    Area     = SelectedArea != null ? (SelectedArea.SettingTOarea()) : null,
                    Location = SelectedLocation != null?SelectedLocation.SettingToLocation() : null,
                                   DateHourDetail = new LocalDateHourDetail()
                    {
                        Date       = Date,
                        StartHour  = StartingHour,
                        Mili       = Convert.ToInt64(DateTime.Now.TimeOfDay.TotalMilliseconds),
                        EndingHour = EndTIme,
                        Duration   = duration
                    },
                    Lucrare          = SelectedWork,
                    PatientName      = SelectedPatient.AllName,
                    Material         = SelectedMaterial,
                    Observation      = Observation,
                    Revenue          = Revenue.HasValue ? Revenue.Value : 0,
                    PatientId        = SelectedPatient.Id,
                    Percent          = Convert.ToDouble((Revenue - cost) * percentage),
                    WasPayedByDental = WasPayedByDental,
                    TechnicianId     = SelectedTechnician != null ? SelectedTechnician.Id : (int?)null,
                    MaterialCost     = MaterialCost,
                    Technician       = SelectedTechnician
                };

                ChangeTotalInfo(intervention, IsInEditMode);
                intervention.Id = DatabaseHandler.Instance.AddIntervention(intervention, LocalCache.Instance.CurrentUser.Id);
                if (IsInEditMode)
                {
                    LocalIntervention = intervention;
                }
                else
                {
                    LocalCache.Instance.AddIntervention(intervention);
                    var patient = LocalCache.Instance.PatientsRepository.Patients.FirstOrDefault(item => item.Id == SelectedPatient.Id);
                    if (patient != null)
                    {
                        patient.Interventions.Add(intervention);
                    }
                }
                SetNewIntervenionDetails(intervention);
                IsPatientComboFocused = false;
                IsPatientComboFocused = true;
                InitData();
            }
            catch (Exception ex)
            {
                MessageBox.Show("A intervenit o eroare la salvare.");
                Log.Error("Error inserting intervention --> Save");
            }
        }
Example #10
0
 private Bitmap GetArea(Bitmap img, SelectedArea area)
 {
     return(img.GetArea(area.X, area.Y, area.Width, area.Height));
 }