Beispiel #1
0
        private double PointsToMap(IDisplayTransformation displayTransform, double dPointSize)
        {
            double num = 0;

            num = (displayTransform != null ? displayTransform.FromPoints(dPointSize) : dPointSize * this.m_dDeviceRatio);
            return(num);
        }
Beispiel #2
0
        private double PointsToMap(IDisplayTransformation displayTransform, double dPointSize)
        {
            double tempPointsToMap = 0;

            if (displayTransform == null)
            {
                tempPointsToMap = dPointSize * m_dDeviceRatio;
            }
            else
            {
                tempPointsToMap = displayTransform.FromPoints(dPointSize);
            }
            return(tempPointsToMap);
        }
        // =========================================================================
        // Thread functions
        // =========================================================================
        private void Redraw(object eventInfo)
        {
            try
            {
                IActiveView activeView = ArcUtils.ActiveView;

                if ((activeView != null) && (!_point.IsEmpty))
                {
                    var display = activeView.ScreenDisplay;
                    IDisplayTransformation dispTrans  = display.DisplayTransformation;
                    const float            arrowSizeh = ((float)ArrowSize) / 2;
                    double    size     = dispTrans.FromPoints(arrowSizeh);
                    double    x        = _point.X;
                    double    y        = _point.Y;
                    double    xmin     = x - size;
                    double    xmax     = x + size;
                    double    ymin     = y - size;
                    double    ymax     = y + size;
                    IEnvelope envelope = new EnvelopeClass {
                        XMin = xmin, XMax = xmax, YMin = ymin, YMax = ymax
                    };
                    display.Invalidate(envelope, true, (short)esriScreenCache.esriNoScreenCache);

                    if (_toUpdateArrow)
                    {
                        StartRedraw();
                    }
                    else
                    {
                        _updateTimer = null;
                    }
                }
            }
            catch (Exception ex)
            {
                Trace.WriteLine(ex.Message, "Arrow.Redraw");
            }
        }
Beispiel #4
0
        // =========================================================================
        // Event handlers
        // =========================================================================
        private void AvEventsAfterDraw(IDisplay display, esriViewDrawPhase phase)
        {
            try
            {
                if ((_measurement != null) && (_point != null))
                {
                    if ((phase == esriViewDrawPhase.esriViewForeground) && _measurement.IsOpen && _measurement.DrawPoint &&
                        (!double.IsNaN(_point.X)) && (!double.IsNaN(_point.Y)))
                    {
                        GsExtension extension = GsExtension.GetExtension();

                        if (extension.InsideScale())
                        {
                            // ReSharper disable UseIndexedProperty
                            // ReSharper disable CSharpWarnings::CS0612
                            display.StartDrawing(display.hDC, (short)esriScreenCache.esriNoScreenCache);
                            IDisplayTransformation dispTrans = display.DisplayTransformation;
                            double distance = dispTrans.FromPoints(PointSize);

                            var fontDisp = new StdFontClass
                            {
                                Bold      = false,
                                Name      = "Arial",
                                Italic    = false,
                                Underline = false,
                                Size      = (decimal)FontSize
                            };

                            ISymbol textSymbol = new TextSymbolClass {
                                Font = fontDisp as IFontDisp
                            };
                            display.SetSymbol(textSymbol);

                            double distanceP = (distance * 3) / 4;
                            IPoint pointText = new PointClass {
                                X = _point.X + distanceP, Y = _point.Y + distanceP
                            };
                            CultureInfo ci   = CultureInfo.InvariantCulture;
                            string      text = _index.ToString(ci);
                            display.DrawText(pointText, text);

                            foreach (var observation in _observations)
                            {
                                double[] obs = observation.Value;

                                if (obs.Length >= 2)
                                {
                                    double xdir    = (_point.X - obs[0]) / 2;
                                    double ydir    = (_point.Y - obs[1]) / 2;
                                    string imageId = observation.Key;

                                    IColor  color      = Converter.ToRGBColor(ObsColor.ContainsKey(imageId) ? ObsColor[imageId] : Color.DarkGray);
                                    ISymbol lineSymbol = new SimpleLineSymbolClass {
                                        Color = color, Width = 1.25
                                    };
                                    display.SetSymbol(lineSymbol);

                                    var polylineClass3 = new PolylineClass();
                                    polylineClass3.AddPoint(new PointClass {
                                        X = _point.X + xdir, Y = _point.Y + ydir
                                    });
                                    polylineClass3.AddPoint(new PointClass {
                                        X = obs[0], Y = obs[1]
                                    });
                                    display.DrawPolyline(polylineClass3);

                                    color      = Converter.ToRGBColor(Color.LightGray);
                                    lineSymbol = new SimpleLineSymbolClass {
                                        Color = color, Width = 0.75
                                    };
                                    display.SetSymbol(lineSymbol);
                                    display.DrawPolyline(polylineClass3);
                                }
                            }

                            display.FinishDrawing();
                            // ReSharper restore CSharpWarnings::CS0612
                            // ReSharper restore UseIndexedProperty
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Trace.WriteLine(ex.Message, "MeasurementPoint.avEventsAfterDraw");
            }
        }
Beispiel #5
0
        public void UpdatePoint(PointMeasurementData measurementData, int index)
        {
            _index = index;
            bool notCreated = NotCreated;
            MeasurementPointS measurementPoint = measurementData.measurementPoint;
            double            x = measurementPoint.x;
            double            y = measurementPoint.y;
            double            z = measurementPoint.z;

            _point = ArcUtils.GsToMapPoint(x, y, z);

            IActiveView            activeView = ArcUtils.ActiveView;
            var                    display    = activeView.ScreenDisplay;
            IDisplayTransformation dispTrans  = display.DisplayTransformation;
            double                 size       = dispTrans.FromPoints(PointSize);
            double                 xmin       = x - size;
            double                 xmax       = x + size;
            double                 ymin       = y - size;
            double                 ymax       = y + size;

            _oldEnvelope = _envelope;

            foreach (var observation in _observations)
            {
                double[] obs = observation.Value;

                if (obs.Length >= 2)
                {
                    double xdir = (_point.X - obs[0]) / 2;
                    double ydir = (_point.Y - obs[1]) / 2;
                    xmin = Math.Min(xmin, _point.X + xdir);
                    ymin = Math.Min(ymin, _point.Y + ydir);
                    xmax = Math.Max(xmax, obs[0]);
                    ymax = Math.Max(ymax, obs[1]);
                }
            }

            _envelope = new EnvelopeClass {
                XMin = xmin, XMax = xmax, YMin = ymin, YMax = ymax
            };
            var avEvents = ArcUtils.ActiveViewEvents;

            if (avEvents != null)
            {
                if (!notCreated)
                {
                    avEvents.AfterDraw -= AvEventsAfterDraw;
                }

                avEvents.AfterDraw += AvEventsAfterDraw;
            }

            IEditor3 editor = ArcUtils.Editor;
            var      sketch = editor as IEditSketch3;

            if ((sketch != null) && (_measurement != null))
            {
                IGeometry geometry = sketch.Geometry;
                int       nrPoints;
                var       ptColl = _measurement.ToPointCollection(geometry, out nrPoints);

                if ((ptColl != null) && _measurement.IsSketch)
                {
                    if (_intId <= nrPoints)
                    {
                        IPoint pointC = ptColl.Point[_intId - 1];

                        if (!IsSame(pointC))
                        {
                            ISketchOperation2 sketchOp = new SketchOperationClass();
                            sketchOp.Start(editor);
                            IPoint point = new PointClass {
                                X = _point.X, Y = _point.Y, Z = _point.Z, M = _index, ZAware = sketch.ZAware
                            };

                            if (_measurement.IsPointMeasurement)
                            {
                                sketch.Geometry = point;
                            }
                            else
                            {
                                ptColl.UpdatePoint((_intId - 1), point);

                                if ((_intId == 1) && ((nrPoints + 1) == ptColl.PointCount))
                                {
                                    ptColl.UpdatePoint((ptColl.PointCount - 1), point);
                                }

                                sketch.Geometry = ptColl as IGeometry;
                            }

                            geometry = sketch.Geometry;

                            if (geometry != null)
                            {
                                sketchOp.Finish(geometry.Envelope, esriSketchOperationType.esriSketchOperationGeneral, geometry);
                            }
                        }
                    }
                    else
                    {
                        ISketchOperation2 sketchOp = new SketchOperationClass();
                        sketchOp.Start(editor);
                        IPoint point = new PointClass {
                            X = _point.X, Y = _point.Y, Z = _point.Z, M = _index, ZAware = sketch.ZAware
                        };
                        int nrPoints2 = ptColl.PointCount;

                        switch (nrPoints2)
                        {
                        case 0:
                            ptColl.AddPoint(point);

                            if (geometry is IPolygon4)
                            {
                                ptColl.AddPoint(point);
                            }
                            break;

                        case 1:
                            ptColl.AddPoint(point);
                            break;

                        default:
                            if (_intId <= (nrPoints + 1))
                            {
                                object point1 = ((_intId - 1) == nrPoints2) ? Type.Missing : (_intId - 1);
                                object point2 = Type.Missing;
                                ptColl.AddPoint(point, ref point1, ref point2);
                            }

                            break;
                        }

                        sketch.Geometry = ptColl as IGeometry;
                        geometry        = sketch.Geometry;

                        if (geometry != null)
                        {
                            sketchOp.Finish(geometry.Envelope, esriSketchOperationType.esriSketchOperationGeneral, geometry);
                        }
                    }
                }
                else
                {
                    if (geometry is IPoint)
                    {
                        if (geometry.IsEmpty)
                        {
                            if ((!double.IsNaN(_point.X)) && (!double.IsNaN(_point.Y)))
                            {
                                if (!_added)
                                {
                                    IApplication application = ArcMap.Application;
                                    ICommandItem tool        = application.CurrentTool;
                                    ICommand     command     = tool.Command;

                                    if (!(command is IEditTool))
                                    {
                                        _added = true;
                                        var    editorZ = editor as IEditorZ;
                                        double zOffset = 0.0;

                                        if (editorZ != null)
                                        {
                                            zOffset         = editorZ.ZOffset;
                                            editorZ.ZOffset = _point.Z;
                                        }

                                        ISketchOperation2 sketchOp = new SketchOperationClass();
                                        sketchOp.Start(editor);
                                        IPoint point = new PointClass {
                                            X = _point.X, Y = _point.Y, Z = _point.Z, M = _index, ZAware = sketch.ZAware
                                        };
                                        sketch.Geometry = point;
                                        geometry        = sketch.Geometry;
                                        sketchOp.Finish(geometry.Envelope, esriSketchOperationType.esriSketchOperationGeneral, geometry);
                                        sketch.FinishSketch();

                                        if (editorZ != null)
                                        {
                                            editorZ.ZOffset = zOffset;
                                        }

                                        _added = false;
                                    }
                                }
                            }
                        }
                        else
                        {
                            var pointC = geometry as IPoint;

                            if (!IsSame(pointC))
                            {
                                if ((!double.IsNaN(_point.X)) && (!double.IsNaN(_point.Y)))
                                {
                                    ISketchOperation2 sketchOp = new SketchOperationClass();
                                    sketchOp.Start(editor);
                                    IPoint point = new PointClass {
                                        X = _point.X, Y = _point.Y, Z = _point.Z, M = _index, ZAware = sketch.ZAware
                                    };
                                    sketch.Geometry = point;
                                    geometry        = sketch.Geometry;
                                    sketchOp.Finish(geometry.Envelope, esriSketchOperationType.esriSketchOperationGeneral, geometry);
                                }
                            }
                        }
                    }
                }
            }

            Update();
        }
 private double PointsToMap(IDisplayTransformation displayTransform, double dPointSize)
 {
   double tempPointsToMap = 0;
   if (displayTransform == null)
     tempPointsToMap = dPointSize * m_dDeviceRatio;
   else
   {
     tempPointsToMap = displayTransform.FromPoints(dPointSize);
   }
   return tempPointsToMap;
 }
        private void AvEventsAfterDraw(IDisplay display, esriViewDrawPhase phase)
        {
            try
            {
                if (phase == esriViewDrawPhase.esriViewForeground)
                {
                    GsExtension extension = GsExtension.GetExtension();

                    if ((extension.InsideScale()) && (!_point.IsEmpty))
                    {
                        // ReSharper disable UseIndexedProperty
                        // ReSharper disable CSharpWarnings::CS0612
                        display.StartDrawing(display.hDC, (short)esriScreenCache.esriNoScreenCache);

                        IDisplayTransformation dispTrans  = display.DisplayTransformation;
                        const float            arrowSizeh = ((float)ArrowSize) / 2;
                        double size = dispTrans.FromPoints(arrowSizeh);

                        double angleh = (_hFov * Math.PI) / 360;
                        double angle  = (((450 - _angle) % 360) * Math.PI) / 180;
                        double angle1 = angle - angleh;
                        double angle2 = angle + angleh;
                        double x      = _point.X;
                        double y      = _point.Y;

                        IPoint point1 = new PointClass {
                            X = x, Y = y
                        };
                        IPoint point2 = new PointClass {
                            X = x + (size * Math.Cos(angle1)), Y = y + (size * Math.Sin(angle1))
                        };
                        IPoint point3 = new PointClass {
                            X = x + (size * Math.Cos(angle2)), Y = y + (size * Math.Sin(angle2))
                        };

                        IPolygon4 polygon      = new PolygonClass();
                        var       polygonPoint = polygon as IPointCollection4;
                        polygonPoint.AddPoint(point1);
                        polygonPoint.AddPoint(point2);
                        polygonPoint.AddPoint(point3);
                        polygonPoint.AddPoint(point1);

                        IColor color = Converter.ToRGBColor(_color);
                        color.Transparency        = _blinking ? BlinkAlpha : NormalAlpha;
                        color.UseWindowsDithering = true;
                        var fillSymbol = new SimpleFillSymbolClass {
                            Color = color, Outline = null
                        };
                        display.SetSymbol(fillSymbol);
                        display.DrawPolygon(polygon);

                        IPolyline polyline      = new PolylineClass();
                        var       polylinePoint = polyline as IPointCollection4;
                        polylinePoint.AddPoint(point2);
                        polylinePoint.AddPoint(point1);
                        polylinePoint.AddPoint(point3);

                        var outlineSymbol = new SimpleLineSymbolClass
                        {
                            Color = Converter.ToRGBColor(_active ? Color.Yellow : Color.Gray),
                            Width = _blinking ? BorderSizeBlinkingArrow : BorderSizeArrow
                        };

                        display.SetSymbol(outlineSymbol);
                        display.DrawPolyline(polyline);
                        display.FinishDrawing();

                        if (_blinking)
                        {
                            var blinkEvent         = new AutoResetEvent(true);
                            var blinkTimerCallBack = new TimerCallback(ResetBlinking);
                            _blinkTimer = new Timer(blinkTimerCallBack, blinkEvent, BlinkTime, -1);
                        }

                        // ReSharper restore CSharpWarnings::CS0612
                        // ReSharper restore UseIndexedProperty
                    }
                }
            }
            catch (Exception ex)
            {
                Trace.WriteLine(ex.Message, "Arrow.avEventsAfterDraw");
            }
        }