public static void ClickKeypad(KeypadKeys key)
            {
                String[,] arr2D = new String[4, 4] {
                    { "Del", "One", "Two", "Three" },
                    { "Clr", "Four", "Five", "Six" },
                    { null, "Seven", "Eight", "Nine" },
                    { null, "Dot", "Zero", "Dash" }
                };
                CustomPoint p = new CustomPoint(0, 0);

                for (int x = 0; x < arr2D.GetLength(0); x++)
                {
                    for (int y = 0; y < arr2D.GetLength(1); y++)
                    {
                        String s = arr2D[y, x];
                        if (s != null && s.Equals(key.ToString()))
                        {
                            p = new CustomPoint(x, y);
                            goto breakLoops;
                        }
                    }
                }
breakLoops:
                SecureClick(150 + (p.GetX() * 140), 110 + (p.GetY() * 75));
                Thread.Sleep(100);
            }
        public void FindMSPointsForSquareAreInCenter()
        {
            finder = new MSPointFinder(square5x5, 0);
            Point  center   = new Point(2.5, 2.5);
            double accuracy = 0.0001;

            List <IMSPoint> msPoints = new List <IMSPoint>();

            msPoints.Add(finder.FindMSPoint(new Point(0, 2.5), new Normal(null, 0, 1, 0)));
            msPoints.Add(finder.FindMSPoint(new Point(2.5, 5), new Normal(null, 0, 0, -1)));
            msPoints.Add(finder.FindMSPoint(new Point(5, 2.5), new Normal(null, 0, -1, 0)));
            msPoints.Add(finder.FindMSPoint(new Point(2.5, 0), new Normal(null, 0, 0, 1)));

            double xAverage = msPoints.Sum(x => x.GetPoint().X) / msPoints.Count;
            double yAverage = msPoints.Sum(x => x.GetPoint().Y) / msPoints.Count;

            Point averagePoint = new Point(xAverage, yAverage);

            Assert.IsTrue(CustomPoint.ClosePoints(averagePoint, center, accuracy));

            foreach (var msPoint in msPoints)
            {
                Assert.IsTrue(CustomPoint.ClosePoints(msPoint.GetPoint(), center, accuracy));
            }
        }
 private void Candle_GetPointerStyle(CustomPoint series, GetPointerStyleEventArgs e)
 {
     if (e.Color == var.GetPaletteBasic[0])
     {
         series.Pointer.Pen.Color = var.GetPaletteBasic[0];
     }
     else
     {
         series.Pointer.Pen.Color = var.GetPaletteBasic[1];
     }
 }
        public override void PreviewDrawing(HashSet <Point> mousePositions)
        {
            if (mousePositions.Count == 1)
            {
                _lastPreviewCirclePoints = new HashSet <IBPoint>();
            }

            foreach (var point in _lastPreviewCirclePoints)
            {
                _bitmap.SetPixel(point.X, point.Y, point.Color);
            }

            _lastPreviewCirclePoints = new HashSet <IBPoint>();

            var startPoint = mousePositions.ElementAt(0);
            var endPoint   = mousePositions.ElementAt(mousePositions.Count - 1);

            var center = new Point((startPoint.X + endPoint.X) / 2, (startPoint.Y + endPoint.Y) / 2);
            var radius = (int)CustomPoint.GetDistance(startPoint.X, startPoint.Y, center.X, center.Y);

            var points = _circleAlgorithm.GetCirclePoints(BPoint.ConvertPointToIBPoint(center), radius);

            var finalPoints = new List <IBPoint>();

            var pixelSize  = Setting.SelectedPixelSize;
            var pixelColor = Setting.SelectedColor;

            foreach (var point in points)
            {
                for (int i = point.X - pixelSize; i < point.X + pixelSize; i++)
                {
                    for (int j = point.Y - pixelSize; j < point.Y + pixelSize; j++)
                    {
                        if (CanvasValidator.IsCursorOutsideCanvas(new Point(i, j)))
                        {
                            continue;
                        }

                        var newPoint = new BPoint(i, j, pixelColor);

                        var currentPixel = _bitmap.GetPixel(i, j);

                        var bPoint = new BPoint(i, j, Color.FromArgb(currentPixel.A, currentPixel.R, currentPixel.G, currentPixel.B));
                        _lastPreviewCirclePoints.Add(bPoint);

                        _bitmap.SetPixel(newPoint);
                    }
                }
            }
        }
        public object Parse(string value)
        {
            var values = value.Replace("[", "").Replace("]", "").Trim().Split(',');

            if (values.Length == 2)
            {
                var obj = new CustomPoint();
                obj.X = int.Parse(values[0]);
                obj.Y = int.Parse(values[1]);

                return(obj);
            }
            else
            {
                throw new Exception("Error parsing CustomPoint");
            }
        }
 // Line PointClick
 public void PointValue_Click(CustomPoint series, int valueIndex, double x, double y)
 {
     if (IndexPointerSelected == valueIndex && LastSeries == series)
     {
         ClearMarks(series);
     }
     else
     {
         ClearMarks();
         series.Marks.Visible = true;
         IndexPointerSelected = valueIndex;
         series.Repaint();
     }
     if (((((BaseChart.Parent as StackLayout).Parent as Grid).Parent as ContentPage).Parent as ChartTabPage).chartSettPage != null)
     {
         ((((BaseChart.Parent as StackLayout).Parent as Grid).Parent as ContentPage).Parent as ChartTabPage).chartSettPage.tView.GetSwitchMarks.firstTime = false;
     }
 }
Example #7
0
        static IList <CustomPoint> TrackPath(string[] wire)
        {
            var path = new List <CustomPoint>();

            foreach (var command in wire)
            {
                var direction = command[0];
                var number    = int.Parse(command.Substring(1));

                for (int i = 1; i <= number; i++)
                {
                    var lastPoint = path.LastOrDefault();

                    if (lastPoint == default(CustomPoint))
                    {
                        lastPoint = new CustomPoint(0, 0, 0);
                    }

                    var lastX = lastPoint.X;
                    var lastY = lastPoint.Y;

                    if (direction == 'R')
                    {
                        lastX++;
                    }
                    else if (direction == 'L')
                    {
                        lastX--;
                    }
                    else if (direction == 'U')
                    {
                        lastY++;
                    }
                    else if (direction == 'D')
                    {
                        lastY--;
                    }

                    path.Add(new CustomPoint(lastX, lastY, lastPoint.Distance + 1));
                }
            }

            return(path);
        }
        public override void SaveDrawing(HashSet <Point> mousePositions)
        {
            var startPoint = mousePositions.ElementAt(0);
            var endPoint   = mousePositions.ElementAt(mousePositions.Count - 1);

            var center = new Point((startPoint.X + endPoint.X) / 2, (startPoint.Y + endPoint.Y) / 2);
            var radius = (int)CustomPoint.GetDistance(startPoint.X, startPoint.Y, center.X, center.Y);

            var points = _circleAlgorithm.GetCirclePoints(BPoint.ConvertPointToIBPoint(center), radius);

            var finalPoints = new List <IBPoint>();

            foreach (var point in points)
            {
                finalPoints.Add(new BPoint(point.X, point.Y));
            }

            var circle = new CircleModel(finalPoints, BPoint.ConvertPointToIBPoint(center), radius);

            Add(circle);
        }
        public static void SecureClick(int x, int y)
        {
            bool correct = false;

            if (prevPoint == null)
            {
                Console.WriteLine("PrevPoint == null, trying to click at: {0}, {1}", x, y);
                for (int i = 0; i < 3; i++)
                {
                    WebHandling.ResetCursor();
                    bool resetCursor = false;
                    for (int j = 0; j < 1000; j++)   //Max 1 second timeout
                    {
                        Thread.Sleep(1);
                        if (IsMouseCorrectPosition(0, 0))
                        {
                            resetCursor = true;
                            break;
                        }
                    }
                    if (resetCursor)
                    {
                        WebHandling.MoveMouseRelative(x, y);
                        int count = 0;
                        for (int j = 0; j < 1000; j++)       //Max 1 second timeout
                        {
                            Thread.Sleep(10);
                            if (IsMouseCorrectPosition(x, y))
                            {
                                if (count >= 3)
                                {
                                    correct = true;
                                    break;
                                }
                                count++;
                            }
                        }
                    }
                    if (correct)
                    {
                        break;
                    }
                }
                if (!correct)
                {
                    throw new Exception("Could not move mouse to absolute Position (" + x + ", " + y + ")");
                }
                WebHandling.ClickAtCursor();
                prevPoint = new CustomPoint(x, y);
            }
            else
            {
                int newX = x - prevPoint.GetX();
                int newY = y - prevPoint.GetY();
                //Console.WriteLine("newX: {0}, newY: {1}, x: {2}, y: {3}, prevX: {4}, prevY: {5}", newX, newY, x, y, prevPoint.GetX(), prevPoint.GetY());
                WebHandling.MoveMouseRelative(newX, newY);
                for (int j = 0; j < 1000; j++)       //Max 1 second timeout
                //Thread.Sleep(1);
                {
                    if (IsMouseCorrectPosition(x, y))
                    {
                        correct = true;
                        break;
                    }
                    else
                    {
                        //Console.WriteLine("Mouse is not in correct Position, should be: {0}, {1}  is: {2}, {3}", x, y, readX, readY);
                    }
                }
                if (!correct)
                {
                    throw new Exception("Could not move mouse to absolute Position (" + newX + ", " + newY + "), relative Position (" + x + ", " + y + ")");
                }
                WebHandling.ClickAtCursor();
                prevPoint = new CustomPoint(x, y);
            }
        }
Example #10
0
        private void ExcelToLineFeatureClass()
        {
            if (cmbStartNoField.SelectedValue == null || cmbEndNoField.SelectedValue == null || cmbLineGroupField.SelectedValue == null)
            {
                return;
            }
            IWorkspaceEdit pWorkspaceEdit = _targetWorkspace as IWorkspaceEdit;

            if (pWorkspaceEdit == null)
            {
                return;
            }
            int lineRowCount   = _excelHelper.GetRowCount(_lineWorksheet.Name);
            int idxSNoColumn   = Convert.ToInt32(cmbStartNoField.SelectedValue);
            int idxENoColumn   = Convert.ToInt32(cmbEndNoField.SelectedValue);
            int idxGroupColumn = Convert.ToInt32(cmbLineGroupField.SelectedValue);

            for (int i = 2; i <= lineRowCount; i++)
            {
                try
                {
                    string groupName;

                    if (checkBoxIsGroup.Checked)
                    {
                        groupName = ((Range)_lineWorksheet.Cells[i, idxGroupColumn]).Value2.ToString().Trim();
                    }
                    else
                    {
                        groupName = _pointWorksheet.Name.Trim();
                    }
                    CustomFeatureClass pCustomFeatureClass = _lineFeatureClassList.FirstOrDefault(c => c.AName == groupName);
                    if (pCustomFeatureClass == null)
                    {
                        try
                        {
                            IFeatureClass pFeatureClass = CreateFeatureClass(string.Format("{0}_Line", groupName), esriGeometryType.esriGeometryPolyline, _targetLineFieldMappingList);
                            pCustomFeatureClass = new CustomFeatureClass
                            {
                                AName        = groupName,
                                FeatureClass = pFeatureClass
                            };
                            _lineFeatureClassList.Add(pCustomFeatureClass);
                        }
                        catch (Exception e)
                        {
                            throw new Exception(string.Format("{0};{1}({2})", i, e.Message, groupName));
                        }
                    }
                    if (pWorkspaceEdit.IsBeingEdited() == false)
                    {
                        pWorkspaceEdit.StartEditing(true);
                        pWorkspaceEdit.StartEditOperation();
                    }
                    IFeatureCursor featureCursor = pCustomFeatureClass.FeatureClass.Insert(true);
                    IFeatureBuffer newFeature    = pCustomFeatureClass.FeatureClass.CreateFeatureBuffer();
                    foreach (FieldMapping fieldMapping in _targetLineFieldMappingList)
                    {
                        try
                        {
                            if (fieldMapping.IndexOriginField <= 0)
                            {
                                continue;
                            }

                            object str = ((Range)_lineWorksheet.Cells[i, fieldMapping.IndexOriginField]).Value2;
                            if (str == null || string.IsNullOrEmpty(str.ToString()) || str.ToString() == "#N/A")
                            {
                                continue;
                            }
                            newFeature.Value[fieldMapping.IndexTargetField] = str.ToString() == "<空>" || str.ToString() == "" ? null : str;
                        }
                        catch (Exception e)
                        {
                            throw new Exception(string.Format("{0};{1}", i, e.Message));
                        }
                    }
                    object sno = ((Range)_lineWorksheet.Cells[i, idxSNoColumn]).Value2;
                    object eno = ((Range)_lineWorksheet.Cells[i, idxENoColumn]).Value2;
                    if (sno == null || string.IsNullOrEmpty(sno.ToString().Trim()) || eno == null || string.IsNullOrEmpty(eno.ToString().Trim()))
                    {
                        continue;
                    }
                    IPolyline polyline = new PolylineClass();
                    IZAware   pZAware  = polyline as IZAware;
                    pZAware.ZAware = true;
                    IMAware pMAware = polyline as IMAware;
                    pMAware.MAware = true;
                    CustomPoint startCustomPoint = _pointList.FirstOrDefault(c => c.No == sno.ToString().Trim());
                    if (startCustomPoint == null)
                    {
                        continue;
                    }
                    polyline.FromPoint = startCustomPoint.Point;
                    CustomPoint endCustomPoint = _pointList.FirstOrDefault(c => c.No == eno.ToString().Trim());
                    if (endCustomPoint == null)
                    {
                        continue;
                    }
                    polyline.ToPoint = endCustomPoint.Point;
                    newFeature.Shape = polyline;
                    featureCursor.InsertFeature(newFeature);
                    Marshal.ReleaseComObject(featureCursor);
                }
                catch (Exception e)
                {
                    throw new Exception(string.Format("{0};{1}", i, e.Message));
                }
            }
        }
Example #11
0
        private void ExcelToPointFeatureClass()
        {
            IWorkspaceEdit pWorkspaceEdit = _targetWorkspace as IWorkspaceEdit;

            if (pWorkspaceEdit == null)
            {
                return;
            }
            int pointRowCount  = _excelHelper.GetRowCount(_pointWorksheet.Name);
            int idxNoColumn    = Convert.ToInt32(cmbNoField.SelectedValue);
            int idxXColumn     = Convert.ToInt32(cmbXField.SelectedValue);
            int idxYColumn     = Convert.ToInt32(cmbYField.SelectedValue);
            int idxZColumn     = Convert.ToInt32(cmbZField.SelectedValue);
            int idxGroupColumn = Convert.ToInt32(cmbPointGroupField.SelectedValue);

            for (int i = 2; i <= pointRowCount; i++)
            {
                try
                {
                    string groupName;
                    if (checkBoxIsGroup.Checked)
                    {
                        groupName = ((Range)_pointWorksheet.Cells[i, idxGroupColumn]).Value2.ToString().Trim();
                    }
                    else
                    {
                        groupName = _pointWorksheet.Name.Trim();
                    }
                    CustomFeatureClass pCustomFeatureClass = _pointFeatureClassList.FirstOrDefault(c => c.AName == groupName);
                    if (pCustomFeatureClass == null)
                    {
                        try
                        {
                            IFeatureClass pFeatureClass = CreateFeatureClass($"{groupName}_Point", esriGeometryType.esriGeometryPoint, _targetPointFieldMappingList);
                            pCustomFeatureClass = new CustomFeatureClass
                            {
                                AName        = groupName,
                                FeatureClass = pFeatureClass
                            };
                            _pointFeatureClassList.Add(pCustomFeatureClass);
                        }
                        catch (Exception e)
                        {
                            throw new Exception($"{i};{e.Message}({groupName})");
                        }
                    }
                    if (pWorkspaceEdit.IsBeingEdited() == false)
                    {
                        pWorkspaceEdit.StartEditing(true);
                        pWorkspaceEdit.StartEditOperation();
                    }
                    IFeatureCursor featureCursor = pCustomFeatureClass.FeatureClass.Insert(true);
                    IFeatureBuffer newFeature    = pCustomFeatureClass.FeatureClass.CreateFeatureBuffer();
                    IPoint         point         = null;
                    string         no            = ((Range)_pointWorksheet.Cells[i, idxNoColumn]).Value2.ToString().Trim();
                    if (chkHasCoordInfo.Checked)
                    {
                        object sX = ((Range)_pointWorksheet.Cells[i, idxXColumn]).Value2;
                        object sY = ((Range)_pointWorksheet.Cells[i, idxYColumn]).Value2;
                        object sZ = ((Range)_pointWorksheet.Cells[i, idxZColumn]).Value2;
                        if (string.IsNullOrEmpty(sX?.ToString()) || string.IsNullOrEmpty(sY?.ToString()) || string.IsNullOrEmpty(sZ?.ToString()))
                        {
                            continue;
                        }
                        double x = Convert.ToDouble(sX);
                        double y = Convert.ToDouble(sY);
                        double z = Convert.ToDouble(sZ);
                        if (checkBoxConvertCoordinateSystem.Checked)
                        {
                            point = GeometryHelper.CreatePoint(y, x, z, 0, true, true);
                        }
                        else
                        {
                            point = GeometryHelper.CreatePoint(x, y, z, 0, true, true);
                        }
                        _pointList.Add(new CustomPoint
                        {
                            No    = no,
                            Point = point
                        });
                    }
                    else
                    {
                        CustomPoint customPoint = _pointList.FirstOrDefault(c => c.No == no);
                        if (customPoint != null)
                        {
                            point = customPoint.Point;
                        }
                    }
                    if (point != null)
                    {
                        newFeature.Shape = point;
                    }
                    foreach (FieldMapping fieldMapping in _targetPointFieldMappingList)
                    {
                        try
                        {
                            if (fieldMapping.IndexOriginField <= 0)
                            {
                                continue;
                            }
                            object obj = ((Range)_pointWorksheet.Cells[i, fieldMapping.IndexOriginField]).Value2;
                            //string str = ((Range)_pointWorksheet.Cells[i, fieldMapping.IndexOriginField]).Value2.ToString();
                            newFeature.Value[fieldMapping.IndexTargetField] = obj == null || obj.ToString() == "<空>" || obj.ToString() == "" ? null : obj;
                            if (point != null)
                            {
                                if (fieldMapping.OriginFieldName == ((KeyValuePair <int, string>)(cmbXField.SelectedItem)).Value)
                                {
                                    newFeature.Value[fieldMapping.IndexTargetField] = point.X.ToString("#0.0000");
                                }
                                else if (fieldMapping.OriginFieldName == ((KeyValuePair <int, string>)(cmbYField.SelectedItem)).Value)
                                {
                                    newFeature.Value[fieldMapping.IndexTargetField] = point.Y.ToString("#0.0000");
                                }
                                else if (fieldMapping.OriginFieldName == ((KeyValuePair <int, string>)(cmbZField.SelectedItem)).Value)
                                {
                                    newFeature.Value[fieldMapping.IndexTargetField] = point.Z.ToString("#0.0000");
                                }
                            }
                        }
                        catch (Exception e)
                        {
                            throw new Exception($"{i};{e.Message}");
                        }
                    }
                    featureCursor.InsertFeature(newFeature);
                    Marshal.ReleaseComObject(featureCursor);
                }
                catch (Exception e)
                {
                    throw new Exception($"{i};{e.Message}");
                }
            }
        }