Beispiel #1
0
        /// <summary>
        /// Instance new layer from image source
        /// </summary>
        /// <param name="imgSource"></param>
        /// <returns></returns>
        public DrawingLayer AddNewLayer(ImageSource imgSource)
        {
            var layer = new DrawingLayer();

            if (!DrawingLayers.Any())
            {
                layer.Width  = imgSource.Width;
                layer.Height = imgSource.Height;
                ActiveLayer  = layer;
            }
            else
            {
                layer.Width  = _viewportManager.WorkAreaWidth;
                layer.Height = _viewportManager.WorkAreaHeight;
            }

            layer.Top  = 0;
            layer.Left = 0;
            //Add image as initial layer element
            var mt = new MovingImageThumb();

            mt.Source    = imgSource;
            mt.Width     = imgSource.Width;
            mt.Height    = imgSource.Height;
            mt.Left      = 0;
            mt.Top       = 0;
            layer.ZIndex = DrawingLayers.Count;
            layer.AddItem(mt);
            DrawingLayers.Add(layer);
            return(layer);
        }
Beispiel #2
0
 /// <summary>
 /// 根据Model进行初始化
 /// </summary>
 /// <param name="point"></param>
 /// <param name="layer"></param>
 /// <param name="snap"></param>
 public override void InitializeFromModel(UnitPoint point, DrawingLayer layer, ISnapPoint snap)
 {
     Width    = layer.Width;
     Color    = layer.Color;
     Selected = true;
     OnMouseDown(null, point, snap);
 }
Beispiel #3
0
 private void btnOption_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
 {
     try
     {
         BackgroundLayer layer                  = m_canvas.Model.BackgroundLayer as BackgroundLayer;
         GridLayer       Grid                   = m_canvas.Model.GridLayer as GridLayer;
         DrawingLayer    Drw                    = m_canvas.Model.ActiveLayer as DrawingLayer;
         Color           nullStorageColor       = m_canvas.Model.NullStorageColor;
         Color           emptyShelfStorageColor = m_canvas.Model.EmptyShelfStorageColor;
         Color           fullShelfStorageColor  = m_canvas.Model.FillShelfStorageColor;
         if (layer != null && Grid != null && Drw != null)
         {
             using (FrmOption frm = new FrmOption(Grid.Enabled, Grid.GridStyle, Grid.Color, layer.Color, Drw.Color, nullStorageColor, emptyShelfStorageColor, fullShelfStorageColor, Drw.Width))
             {
                 if (frm.ShowDialog() == DialogResult.OK)
                 {
                     Grid.Enabled   = frm.GridEnable;
                     Grid.GridStyle = frm.GridStyle;
                     Grid.Color     = frm.GridColor;
                     layer.Color    = frm.BackGroudColor;
                     Drw.Color      = frm.PenColor;
                     Drw.Width      = frm.PenWidth;
                     m_canvas.Model.NullStorageColor       = frm.NullStorageColor;
                     m_canvas.Model.EmptyShelfStorageColor = frm.EmptyShelfStorageColor;
                     m_canvas.Model.FillShelfStorageColor  = frm.FullShelfStorageColor;
                     m_canvas.DoInvalidate(true);
                 }
             }
         }
     }
     catch (Exception ex)
     { MsgBox.ShowError(ex.Message); }
 }
        /// <summary>
        /// Returns the current backbuffer from the swapchain used for drawing
        /// </summary>
        public override DrawingLayer GetCurrentDrawingLayer()
        {
            /* Get the current back buffer */
            var backbuffer = Resource.FromSwapChain<Texture2D>(InternalSwapChain, 0);

            DrawingLayer ret;

            /* Search if we have delt with this backbuffer before because we would have already
             * wrapped it in our drawing layer and added it to our cache */
            foreach (var layer in m_drawingLayers)
            {
                ret = layer;
                /* I felt safe comparing pointers to make sure they are the same ref...*/
                if (layer.RenderTargetTexture.InternalTexture2D.ComPointer == backbuffer.ComPointer)
                    return ret;
            }

            /* Wrap our backbuffer in a DrawingLayer */
            ret = new DrawingLayer(m_directCanvasFactory, new RenderTargetTexture(backbuffer));

            /* Save it in our cache */
            m_drawingLayers.Add(ret);

            return ret;
        }
Beispiel #5
0
        internal void Fill(DrawingLayer drawingLayer, Brushes.Brush brush)
        {
            var bounds = GetBoundsInverted();
            drawingLayer.PushState();
            
            BrushHelper.PrepareBrush(brush, drawingLayer, bounds, GetCurrentTransform(), Matrix3x2.Identity);

            if (m_transformedGeometry != null)
            {
                m_transformedGeometry.Dispose();
                m_transformedGeometry = null;
            }

            m_transformedGeometry = new TransformedGeometry(InternalRenderTargetResourceOwner.InternalRenderTarget.Factory, 
                                                            GetInternalGeometry(),
                                                            GetCurrentTransform());

            if (m_mesh == null)
                drawingLayer.D2DRenderTarget.InternalRenderTarget.FillGeometry(m_transformedGeometry, brush.InternalBrush);
            else
            {
                drawingLayer.D2DRenderTarget.InternalRenderTarget.AntialiasMode = AntialiasMode.Aliased;
                drawingLayer.D2DRenderTarget.InternalRenderTarget.FillMesh(m_mesh, brush.InternalBrush);
            }

            drawingLayer.PopState();
        }
Beispiel #6
0
        /// <summary>
        /// Applies the control template to the window
        /// </summary>
        public override void OnApplyTemplate()
        {
            base.OnApplyTemplate();

            if (System.ComponentModel.DesignerProperties.GetIsInDesignMode(this))
            {
                return;
            }

            _scaleTransform.CenterX = 0.5;
            _scaleTransform.CenterY = 0.5;

            _ScrollContainer = (ScrollViewer)GetTemplateChild("PART_ScrollViewer");

            _ImgContent = (Image)GetTemplateChild("PART_Image");
            _ImgContent.LayoutTransform             = _scaleTransform;
            _ImgContent.PreviewMouseWheel          += new MouseWheelEventHandler(_ImgContent_PreviewMouseWheel);
            _ImgContent.PreviewMouseLeftButtonDown += new MouseButtonEventHandler(_ImgContent_PreviewMouseLeftButtonDown);
            _ImgContent.PreviewMouseLeftButtonUp   += new MouseButtonEventHandler(_ImgContent_PreviewMouseLeftButtonUp);
            _ImgContent.PreviewMouseMove           += new MouseEventHandler(_ImgContent_PreviewMouseMove);

            this.PreviewKeyDown += new KeyEventHandler(_ImgContent_PreviewKeyUp);

            _DrawingLayer = (DrawingLayer)GetTemplateChild("PART_DrawingLayer");
            _DrawingLayer.PreviewMouseWheel += new MouseWheelEventHandler(_DrawingLayout_PreviewMouseWheel);
        }
Beispiel #7
0
 /// <summary>
 /// 从模型中初始化矩形(点状)
 /// </summary>
 /// <param name="point"></param>
 /// <param name="layer"></param>
 /// <param name="snap"></param>
 public override void InitializeFromModel(UnitPoint point, DrawingLayer layer, ISnapPoint snap)
 {
     P1       = P2 = point;
     Width    = layer.Width;
     Color    = layer.Color;
     Selected = true;
 }
Beispiel #8
0
        void CreateNewPath()
        {
            CGPath path = new CGPath();

            path.AddRect(new CGRect(0, 0, 1, 1));
            DrawingLayer.SetBasicPath(path);
        }
Beispiel #9
0
 /// <summary>
 /// 从模型中初始化(点状)
 /// </summary>
 /// <param name="point"></param>
 /// <param name="layer"></param>
 /// <param name="snap"></param>
 public override void InitializeFromModel(UnitPoint point, DrawingLayer layer, ISnapPoint snap)
 {
     P1       = P2 = P3 = P4 = m_curPoint = point;
     Width    = layer.Width;
     Color    = layer.Color;
     Selected = true;
     //Console.WriteLine(""+point.X+" "+point.Y);
 }
 public override void InitializeFromModel(UnitPoint point, DrawingLayer layer, ISnapPoint snap)
 {
     m_p1 = m_p2 = point;
     UpdateCtrlPts();
     Width    = layer.Width;
     Color    = layer.Color;
     Selected = true;
 }
 public override void InitializeFromModel(UnitPoint point, DrawingLayer layer, ISnapPoint snap)
 {
     m_center = new UnitPoint(0.0f, 0.0f);
     Width    = layer.Width;
     Color    = layer.Color;
     OnMouseDown(null, point, snap);
     Selected = true;
 }
Beispiel #12
0
        void CreateNewPath()
        {
            CGPath path = new CGPath();

            path.MoveToPoint(x1, y1);
            path.AddLineToPoint(x2, y2);
            DrawingLayer.SetBasicPath(path);
        }
Beispiel #13
0
 /// <summary>
 /// 从模型中初始化矩形(点状)
 /// </summary>
 /// <param name="point"></param>
 /// <param name="layer"></param>
 /// <param name="snap"></param>
 public override void InitializeFromModel(UnitPoint point, DrawingLayer layer, ISnapPoint snap)
 {
     P1    = P2 = point;
     Width = layer.Width;
     Color = layer.Color;
     //OnMouseDown(null, point, snap);
     Selected = true;
     //Console.WriteLine(""+point.X+" "+point.Y);
 }
        protected override void ValueChanged(object oldValue, object newValue)
        {
            if (newValue is DrawingLayer == false)
            {
                throw new Exception("Set type must be a DrawingLayer.");
            }

            m_drawingLayer = (DrawingLayer)newValue;
        }
Beispiel #15
0
 public override void InitializeFromModel(UnitPoint point, DrawingLayer layer, ISnapPoint snap)
 {
     try
     {
         Width    = layer.Width;
         Color    = layer.Color;
         Selected = true;
     }
     catch (Exception ex)
     { throw ex; }
 }
Beispiel #16
0
 public MapView(IGuiServices guiServices,
                MapBackgroundLayer mapLayer,
                CitiesLayer citiesLayer,
                ArmiesLayer armiesLayer,
                MapGuiLayer mapGuiLayer,
                DrawingLayer drawingLayer,
                ModalLayer messagesLayer) : base(guiServices)
 {
     Layers = new List <MapLayer> {
         mapLayer, citiesLayer, armiesLayer, mapGuiLayer, drawingLayer, messagesLayer
     };
 }
Beispiel #17
0
        public void SetPoints(CGPoint[] points)
        {
            CGPath path = new CGPath();

            path.AddLines(points);

            if (this is PolygonUIView)
            {
                path.CloseSubpath();
            }
            DrawingLayer.SetBasicPath(path);
        }
Beispiel #18
0
 /// <summary>
 /// 初始化
 /// </summary>
 public override void InitializeFromModel(UnitPoint point, DrawingLayer layer, ISnapPoint snap)
 {
     try
     {
         Width    = layer.Width;
         Color    = layer.Color;
         m_p1     = m_p2 = m_p3 = m_p4 = point;
         Selected = true;
         OnMouseDown(null, point, snap);
     }
     catch (Exception ex)
     { throw ex; }
 }
Beispiel #19
0
        async private Task RenderSelection(IFeatureLayer fLayer, ICancelTracker cancelTracker)
        {
            if (fLayer == null || !(fLayer is IFeatureSelection))
            {
                return;
            }

            if (fLayer.SelectionRenderer == null)
            {
                return;
            }

            IFeatureSelection fSelection = (IFeatureSelection)fLayer;

            if (fSelection.SelectionSet == null || fSelection.SelectionSet.Count == 0)
            {
                return;
            }

            RenderFeatureLayerSelection rlt = new RenderFeatureLayerSelection(this, fLayer, cancelTracker);

            //rlt.Render();

            //Thread thread = new Thread(new ThreadStart(rlt.Render));
            //thread.Start();

            DrawingLayer.BeginInvoke(fLayer.Title, new AsyncCallback(AsyncInvoke.RunAndForget), null);

            await rlt.Render();

            //while (thread.IsAlive)
            //{
            //    Thread.Sleep(10);
            //    if (DoRefreshMapView != null && (count % 100) == 0 && cancelTracker.Continue)
            //    {
            //        DoRefreshMapView();
            //    }
            //    count++;
            //}
            if (cancelTracker.Continue)
            {
                DoRefreshMapView?.Invoke();
            }
        }
Beispiel #20
0
 public override void InitializeFromModel(UnitPoint point, DrawingLayer layer, ISnapPoint snap)
 {
     base.InitializeFromModel(point, layer, snap);
     m_perSnap = snap as PerpendicularSnapPoint;
     m_tanSnap = snap as TangentSnapPoint;
 }
Beispiel #21
0
        static public void PrepareBrush(Brush brush, DrawingLayer drawingLayer, RectangleF bounds, Matrix3x2 localTransform, Matrix3x2 worldTransform)
        {
            var alignment = brush.Alignment;
            var brushSize = brush.BrushSize;

            Matrix3x2 currentBrushTransform = Matrix3x2.Identity;
            
            if (brush.Transform != null)
            {
                switch (alignment)
                {
                    case BrushAlignment.DrawingLayerAbsolute:
                        currentBrushTransform = brush.Transform.GetTransform();
                        break;
                    case BrushAlignment.DrawingLayerRelative:
                        currentBrushTransform = brush.Transform.GetTransformRelative(new RectangleF(0,0, drawingLayer.Width, drawingLayer.Height));
                        break;
                    case BrushAlignment.GeometryAbsolute:
                        currentBrushTransform = brush.Transform.GetTransform();
                        break;
                    case BrushAlignment.GeometryRelative:
                        currentBrushTransform = brush.Transform.GetTransformRelative(bounds);
                        break;
                    default:
                        throw new ArgumentOutOfRangeException();
                }
            }

            switch (alignment)
            {
                case BrushAlignment.DrawingLayerAbsolute:
                    brush.InternalBrush.Transform = currentBrushTransform * Matrix3x2.Invert(worldTransform);
                    break;
                case BrushAlignment.DrawingLayerRelative:
                    {
                        var scaleMatrix = Matrix3x2.Scale(drawingLayer.Width / brushSize.Width,
                                                          drawingLayer.Height / brushSize.Height);

                        brush.InternalBrush.Transform = scaleMatrix * currentBrushTransform * Matrix3x2.Invert(worldTransform);
                    }
                    break;
                case BrushAlignment.GeometryAbsolute:
                    {
                        var translate = Matrix3x2.Translation(bounds.InternalRectangleF.Location);
                        brush.InternalBrush.Transform = translate * localTransform * currentBrushTransform;
                    }
                    break;
                case BrushAlignment.GeometryRelative:
                    {
                        var scaleMatrix = Matrix3x2.Scale(bounds.Width / brushSize.Width,
                                                          bounds.Height / brushSize.Height);

                        var translate = Matrix3x2.Translation(bounds.InternalRectangleF.Location);

                        brush.InternalBrush.Transform = scaleMatrix * translate * localTransform * currentBrushTransform;
                    }
                    break;
                default:
                    throw new ArgumentOutOfRangeException();
            }
        }
 public void CopyFromLayer(DrawingLayer layer)
 {
     m_layer.Copy(layer, false);
     m_count = layer.Count;
 }
Beispiel #23
0
 public void CopyToLayer(DrawingLayer layer)
 {
     layer.Copy(m_layer, false);
 }
Beispiel #24
0
 public void SetFillMode(bool isNonzeroFill)
 {
     DrawingLayer.SetIsNonzeroFill(isNonzeroFill);
 }
Beispiel #25
0
 public void SetRadiusY(double radiusY)
 {
     RadiusY = new nfloat(radiusY);
     DrawingLayer.SetNeedsDisplay();
 }
Beispiel #26
0
 public override void InitializeFromModel(UnitPoint point, DrawingLayer layer, ISnapPoint snap)
 {
     Width = layer.Width;
     Color = layer.Color;
     OnMouseDown(null, point, snap);
     Selected = true;
 }
Beispiel #27
0
 public void SetPath(CoreGraphics.CGPathPlus path)
 {
     DrawingLayer.SetBasicPath(path);
     DrawingLayer.SetIsNonzeroFill(path == null ? false : path.IsNonzeroFill);
 }
Beispiel #28
0
        private void actBZCurve_Execute(object sender, ExecuteEventArgs e)
        {
            var cadView = this.CadView;

            if (cadView == null)
            {
                return;
            }
            var surfaceLayer = SurfaceLayer.GetSurfaceLayer(cadView);

            if (surfaceLayer == null)
            {
                return;
            }
            var surface = surfaceLayer.Surface;

            if (surface == null)
            {
                return;
            }

            cadView.SelectionSet.Clear();
            surface.BeginUpdate("Сглаживание структурной линии");

            try
            {
                var line = surfaceLayer.SelectOneStructureLine(null, "Выберите структурную линию") as StructureLine;
                if (line == null)
                {
                    return;
                }

                double         step      = 10.0;
                GetPointResult gpr_delta = Topomatic.Cad.View.Hints.CadCursors.GetDoubleWithDefault(cadView, ref step, "Укажите укажите размер сегмента после сглаживания, м <10>:");
                if (gpr_delta != GetPointResult.Accept)
                {
                    return;
                }

                int            Nb       = 3;
                GetPointResult gpr_code = Topomatic.Cad.View.Hints.CadCursors.GetIntegerWithDefault(cadView, ref Nb, "Укажите количество сегментов для разбиения коротких участков <3>:");
                if (gpr_code != GetPointResult.Accept)
                {
                    return;
                }

                var editor = new PointEditor(surface);

                var newline = new Topomatic.Sfc.StructureLine();

                newline.CopyProperty(line);

                SurfacePoint[,] segments = new SurfacePoint[(line.Count - 1), 4];

                var node  = line[0];
                var point = surface.Points[node.Index];
                segments[0, 0] = point.Clone();


                double coef = 0.341, raznicaS = 1.0, raznicaF = 1.0;

                for (int i = 0; i < line.Count - 2; i++)
                {
                    double LS = 0, LF = 0;

                    var nodeS  = line[i];
                    var pointS = surface.Points[nodeS.Index].Clone();
                    var nodeF  = line[i + 1];
                    var pointF = surface.Points[nodeF.Index].Clone();
                    var nodeN  = line[i + 2];
                    var pointN = surface.Points[nodeN.Index].Clone();

                    LS = Math.Sqrt(Math.Pow(pointF.Vertex.X - pointS.Vertex.X, 2) + Math.Pow(pointF.Vertex.Y - pointS.Vertex.Y, 2) + Math.Pow(pointF.Vertex.Z - pointS.Vertex.Z, 2));
                    LF = Math.Sqrt(Math.Pow(pointN.Vertex.X - pointF.Vertex.X, 2) + Math.Pow(pointN.Vertex.Y - pointF.Vertex.Y, 2) + Math.Pow(pointN.Vertex.Z - pointF.Vertex.Z, 2));

                    double D1 = DirAngle(pointS, pointF);
                    double D2 = DirAngle(pointF, pointN);
                    double gamma = 0, C1, C2;

                    //if (D1 > D2)
                    //{
                    //    gamma = Math.PI + D2 - D1;
                    //}
                    //else if (D2 < D1)
                    //{
                    //    gamma = Math.PI + D1 - D2;
                    //}
                    //else { gamma = Math.PI; }

                    gamma = D2 - D1 + 2 * 3.1415926535897932384626433832795;


                    if (gamma < Math.PI)
                    {
                        C1 = D2 + ((Math.PI - gamma) / 2) + Math.PI * 1.5;
                        C2 = C1 + Math.PI;
                    }
                    else
                    {
                        if (D1 > D2)
                        {
                            C1 = D2 + ((Math.PI - gamma) / 2) + Math.PI * 1.5;
                            C2 = C1 + Math.PI;
                        }
                        else
                        {
                            C1 = D2 - gamma + ((gamma - Math.PI) / 2) + Math.PI * 0.5;
                            C2 = C1 + Math.PI;
                        }
                    }


                    //if(D1>D2)
                    //{
                    //    double temp = C2;
                    //    C2 = C1;
                    //    C1 = temp;
                    //}

                    if (LS / LF > 10)
                    {
                        LS = LF;
                    }

                    if (LF / LS > 10)
                    {
                        LF = LS;
                    }


                    double dy = LS * coef * Math.Cos(C1) * raznicaS;
                    double dx = LS * coef * Math.Sin(C1) * raznicaS;

                    var vectorFC1 = new Vector3D(pointF.Vertex.X + dx, pointF.Vertex.Y + dy, pointF.Vertex.Z);

                    dy = LF * coef * Math.Cos(C2) * raznicaF;
                    dx = LF * coef * Math.Sin(C2) * raznicaF;
                    var vectorFC2 = new Vector3D(pointF.Vertex.X + dx, pointF.Vertex.Y + dy, pointF.Vertex.Z);

                    SurfacePoint pointFC1 = new SurfacePoint(vectorFC1);
                    SurfacePoint pointFC2 = new SurfacePoint(vectorFC2);

                    segments[i, 3]     = pointF.Clone();
                    segments[i + 1, 0] = pointF.Clone();

                    if (i == 0)
                    {
                        //double C0 = D1 - ((Math.PI - gamma) / 2);
                        double C0 = C1 - 3.14 - gamma;
                        dy = LS * coef * Math.Cos(C0);
                        dx = LS * coef * Math.Sin(C0);
                        var          vectorSC0 = new Vector3D(pointS.Vertex.X + dx, pointS.Vertex.Y + dy, pointS.Vertex.Z);
                        SurfacePoint pointSC1  = new SurfacePoint(vectorSC0);
                        segments[0, 1] = pointSC1;
                    }

                    if (i == line.Count - 3)
                    {
                        //double C3 = Math.PI + D2 + ((Math.PI - gamma) / 2);
                        double C3 = C2 + 3.14 + gamma;
                        dy = LF * coef * Math.Cos(C3);
                        dx = LF * coef * Math.Sin(C3);
                        var          vectorNC3 = new Vector3D(pointN.Vertex.X + dx, pointN.Vertex.Y + dy, pointN.Vertex.Z);
                        SurfacePoint pointNC3  = new SurfacePoint(vectorNC3);
                        segments[i + 1, 2] = pointNC3;
                        segments[i + 1, 3] = pointN.Clone();
                    }

                    segments[i, 2]     = pointFC1;
                    segments[i + 1, 1] = pointFC2;
                }

                var drawingLayer = DrawingLayer.GetDrawingLayer(cadView);
                if (drawingLayer == null)
                {
                    return;
                }
                var drawing = drawingLayer.Drawing;
                if (drawing == null)
                {
                    return;
                }


                drawing.ActiveSpace.BeginUpdate();

                try
                {
                    /*for (int i = 0; i < segments.GetLength(0); i++)
                     * {
                     *  var cLineS = new Topomatic.Dwg.Entities.DwgPolyline();
                     *  var cLineF = new Topomatic.Dwg.Entities.DwgPolyline();
                     *
                     *  var posS1 = new Topomatic.Cad.Foundation.Vector2D(segments[i, 0].Vertex.X, segments[i, 0].Vertex.Y);
                     *  cLineS.Add(new Topomatic.Cad.Foundation.BugleVector2D(posS1, 0));
                     *  var posF1 = new Topomatic.Cad.Foundation.Vector2D(segments[i, 1].Vertex.X, segments[i, 1].Vertex.Y);
                     *  cLineS.Add(new Topomatic.Cad.Foundation.BugleVector2D(posF1, 0));
                     *  var posS2 = new Topomatic.Cad.Foundation.Vector2D(segments[i, 2].Vertex.X, segments[i, 2].Vertex.Y);
                     *  cLineF.Add(new Topomatic.Cad.Foundation.BugleVector2D(posS2, 0));
                     *  var posF2 = new Topomatic.Cad.Foundation.Vector2D(segments[i, 3].Vertex.X, segments[i, 3].Vertex.Y);
                     *  cLineF.Add(new Topomatic.Cad.Foundation.BugleVector2D(posF2, 0));
                     *
                     *  drawing.ActiveSpace.Add(cLineS);
                     *  drawing.ActiveSpace.Add(cLineF);
                     * }*/
                }
                finally
                {
                    drawing.ActiveSpace.EndUpdate();
                }

                for (int i = 0; i < segments.GetLength(0); i++)
                {
                    double t = 0.0;
                    //int step = 100;
                    double L1 = Math.Sqrt(Math.Pow(segments[i, 3].Vertex.X - segments[i, 0].Vertex.X, 2) + //длина исходного сегмента
                                          Math.Pow(segments[i, 3].Vertex.Y - segments[i, 0].Vertex.Y, 2) +
                                          Math.Pow(segments[i, 3].Vertex.Z - segments[i, 0].Vertex.Z, 2));

                    double L3 = Math.Sqrt(Math.Pow(segments[i, 1].Vertex.X - segments[i, 0].Vertex.X, 2) +//длина полилинии, проходящей через начальную, две контрольные и конечную точки
                                          Math.Pow(segments[i, 1].Vertex.Y - segments[i, 0].Vertex.Y, 2) +
                                          Math.Pow(segments[i, 1].Vertex.Z - segments[i, 0].Vertex.Z, 2)) +

                                Math.Sqrt(Math.Pow(segments[i, 2].Vertex.X - segments[i, 1].Vertex.X, 2) +
                                          Math.Pow(segments[i, 2].Vertex.Y - segments[i, 1].Vertex.Y, 2) +
                                          Math.Pow(segments[i, 2].Vertex.Z - segments[i, 1].Vertex.Z, 2)) +

                                Math.Sqrt(Math.Pow(segments[i, 3].Vertex.X - segments[i, 2].Vertex.X, 2) +
                                          Math.Pow(segments[i, 3].Vertex.Y - segments[i, 2].Vertex.Y, 2) +
                                          Math.Pow(segments[i, 3].Vertex.Z - segments[i, 2].Vertex.Z, 2));

                    double L2 = 1.01 * (L3 + L1) / 2;
                    int    N  = (Int32)Math.Round(L2 / step);//количество шагов кривой

                    if (N < Nb)
                    {
                        N = Nb;
                    }

                    double         d = 1.0 / N; //шаг дельта t
                    SurfacePoint[] p = new SurfacePoint[4];

                    for (int j = 0; j < 4; j++)
                    {
                        p[j] = segments[i, j];
                    }

                    SurfacePoint q = new SurfacePoint();
                    //SurfacePoint r = CastR(p, t, 3, 0).Clone();
                    SurfacePoint r = segments[i, 0].Clone();

                    var index = new Topomatic.Sfc.PointEditor(surface).Add(r);
                    newline.Add(index);

                    for (int k = 0; k < N - 1; k++)
                    {
                        t           += d;
                        q            = CastR(p, t, 3, 0).Clone();
                        r            = q.Clone();
                        r.IsExtended = true;
                        r.IsDynamic  = true;
                        index        = new Topomatic.Sfc.PointEditor(surface).Add(r);
                        newline.Add(index);
                    }
                }
                var ind = new Topomatic.Sfc.PointEditor(surface).Add(segments[segments.GetLength(0) - 1, 3]);
                newline.Add(ind);

                surface.StructureLines.Add(newline);

                for (int l = 0; l < line.Count; l++)
                {
                    var delpoint = new StructureLineNode(line[l].Index);
                    line.Remove(delpoint);
                    editor.Remove(delpoint.Index);
                }
                surface.StructureLines.Remove(line);
            }
            finally
            {
                surface.EndUpdate();
            }
        }
Beispiel #29
0
 public OptionsLayer(DrawingLayer layer)
 {
     CopyFromLayer(layer);
 }
Beispiel #30
0
 public void CopyFromLayer(DrawingLayer layer)
 {
     m_layer.Copy(layer, false);
     m_count = layer.Count;
 }
Beispiel #31
0
        internal void CopyToDrawingLayer(DrawingLayer drawingLayer, Rectangle destRect)
        {
            IntPtr pBuffer;
            int bufferSize;
            int stride = 0;
            int hr = 0;

            var rect = new WICRect
            {
                X = 0,
                Y = 0,
                Width = Width,
                Height = Height
            };

            IWICBitmapLock imageLock;

            hr = m_internalBitmap.Lock(ref rect,
                                       WICBitmapLockFlags.WICBitmapLockRead,
                                       out imageLock);

            if(hr != 0)
                throw new Exception("Could not lock the image");

            hr = imageLock.GetDataPointer(out bufferSize, out pBuffer);

            imageLock.GetStride(out stride);

            if(destRect.IsEmpty)
                drawingLayer.D2DRenderTarget.InternalBitmap.FromMemory(pBuffer, stride);
            else
                drawingLayer.D2DRenderTarget.InternalBitmap.FromMemory(pBuffer, 
                                                                       stride, 
                                                                       destRect.GetInternalRect());

            Marshal.ReleaseComObject(imageLock);
        }
Beispiel #32
0
 internal void CopyToDrawingLayer(DrawingLayer drawingLayer)
 {
     CopyToDrawingLayer(drawingLayer, Rectangle.Empty);
 }
Beispiel #33
0
        async override public Task <bool> RefreshMap(DrawPhase phase, ICancelTracker cancelTracker)
        {
            base.ResetRequestExceptions();
            bool printerMap = (this.GetType() == typeof(PrinterMap));

            try
            {
                _original.FireStartRefreshMap();

                using (var datasetCachingContext = new DatasetCachingContext(this))
                {
                    this.IsRefreshing = true;

                    _lastException = null;

                    if (_canvas != null && phase == DrawPhase.Graphics)
                    {
                        return(true);
                    }

                    #region Start Drawing/Initialisierung

                    this.ZoomTo(m_actMinX, m_actMinY, m_actMaxX, m_actMaxY);

                    if (cancelTracker == null)
                    {
                        cancelTracker = new CancelTracker();
                    }

                    IGeometricTransformer geoTransformer = GeometricTransformerFactory.Create();

                    //geoTransformer.ToSpatialReference = this.SpatialReference;
                    if (!printerMap)
                    {
                        if (phase == DrawPhase.All)
                        {
                            DisposeStreams();
                        }

                        if (_bitmap != null && (_bitmap.Width != iWidth || _bitmap.Height != iHeight))
                        {
                            if (!DisposeImage())
                            {
                                return(false);
                            }
                        }

                        if (_bitmap == null)
                        {
                            //DisposeStreams();
                            _bitmap = GraphicsEngine.Current.Engine.CreateBitmap(iWidth, iHeight, GraphicsEngine.PixelFormat.Rgba32);
                            //if (NewBitmap != null && cancelTracker.Continue) NewBitmap(_image);
                        }

                        _canvas = _bitmap.CreateCanvas();
                        //this.dpi = /*96f*/ /* _canvas.DpiX*/ GraphicsEngine.Current.Engine.ScreenDpi;

                        // NewBitmap immer aufrufen, da sonst neuer DataView nix mitbekommt
                        if (NewBitmap != null && cancelTracker.Continue)
                        {
                            NewBitmap?.BeginInvoke(_bitmap, new AsyncCallback(AsyncInvoke.RunAndForget), null);
                        }

                        using (var brush = GraphicsEngine.Current.Engine.CreateSolidBrush(_backgroundColor))
                        {
                            _canvas.FillRectangle(brush, new GraphicsEngine.CanvasRectangle(0, 0, iWidth, iHeight));
                        }
                    }

                    #endregion

                    #region Geometry

                    if (Bit.Has(phase, DrawPhase.Geography))
                    //if (phase == DrawPhase.All || phase == DrawPhase.Geography)
                    {
                        LabelEngine.Init(this.Display, printerMap);

                        this.GeometricTransformer = geoTransformer;

                        // Thread für MapServer Datasets starten...
                        #region WebServiceLayer
                        List <IWebServiceLayer> webServices;
                        if (this.TOC != null)
                        {
                            webServices = ListOperations <IWebServiceLayer> .Swap(this.TOC.VisibleWebServiceLayers);
                        }
                        else
                        {
                            webServices = new List <IWebServiceLayer>();
                            foreach (IDatasetElement layer in this.MapElements)
                            {
                                if (!(layer is IWebServiceLayer))
                                {
                                    continue;
                                }

                                if (((ILayer)layer).Visible)
                                {
                                    webServices.Add((IWebServiceLayer)layer);
                                }
                            }
                        }
                        int webServiceOrder = 0;
                        foreach (IWebServiceLayer element in webServices)
                        {
                            if (!element.Visible)
                            {
                                continue;
                            }

                            RenderServiceRequest srt = new RenderServiceRequest(this, element, webServiceOrder++);
                            srt.finish += new RenderServiceRequest.RequestThreadFinished(MapRequestThread_finished);
                            //Thread thread = new Thread(new ThreadStart(srt.ImageRequest));
                            m_imageMerger.max++;
                            //thread.Start();
                            var task = srt.ImageRequest();  // start the task...
                        }
                        #endregion

                        #region Layerlisten erstellen
                        List <ILayer> layers;
                        if (this.TOC != null)
                        {
                            if (this.ToString() == "gView.MapServer.Instance.ServiceMap")
                            {
                                layers = ListOperations <ILayer> .Swap(this.TOC.Layers);
                            }
                            else
                            {
                                layers = ListOperations <ILayer> .Swap(this.TOC.VisibleLayers);
                            }
                        }
                        else
                        {
                            layers = new List <ILayer>();
                            foreach (IDatasetElement layer in this.MapElements)
                            {
                                if (!(layer is ILayer))
                                {
                                    continue;
                                }

                                if (((ILayer)layer).Visible)
                                {
                                    layers.Add((ILayer)layer);
                                }
                            }
                        }

                        List <IFeatureLayer> labelLayers = this.OrderedLabelLayers(layers);

                        #endregion

                        #region Renderer Features

                        foreach (ILayer layer in layers)
                        {
                            if (!cancelTracker.Continue)
                            {
                                break;
                            }

                            if (!layer.RenderInScale(this))
                            {
                                continue;
                            }

                            SetGeotransformer(layer, geoTransformer);

                            DateTime startTime = DateTime.Now;

                            FeatureCounter fCounter = new FeatureCounter();
                            if (layer is IFeatureLayer)
                            {
                                if (layer.Class?.Dataset is IFeatureCacheDataset)
                                {
                                    await((IFeatureCacheDataset)layer.Class.Dataset).InitFeatureCache(datasetCachingContext);
                                }

                                IFeatureLayer fLayer = (IFeatureLayer)layer;
                                if (fLayer.FeatureRenderer == null &&
                                    (
                                        fLayer.LabelRenderer == null ||
                                        (fLayer.LabelRenderer != null && fLayer.LabelRenderer.RenderMode != LabelRenderMode.RenderWithFeature)
                                    ))
                                {
                                    //continue;
                                }
                                else
                                {
                                    RenderFeatureLayer rlt = new RenderFeatureLayer(this, datasetCachingContext, fLayer, cancelTracker, fCounter);
                                    if (fLayer.LabelRenderer != null && fLayer.LabelRenderer.RenderMode == LabelRenderMode.RenderWithFeature)
                                    {
                                        rlt.UseLabelRenderer = true;
                                    }
                                    else
                                    {
                                        rlt.UseLabelRenderer = labelLayers.IndexOf(fLayer) == 0;  // letzten Layer gleich mitlabeln
                                    }

                                    if (rlt.UseLabelRenderer)
                                    {
                                        labelLayers.Remove(fLayer);
                                    }

                                    if (cancelTracker.Continue)
                                    {
                                        DrawingLayer?.BeginInvoke(layer.Title, new AsyncCallback(AsyncInvoke.RunAndForget), null);
                                    }

                                    await rlt.Render();
                                }
                            }
                            if (layer is IRasterLayer && ((IRasterLayer)layer).RasterClass != null)
                            {
                                IRasterLayer rLayer = (IRasterLayer)layer;
                                if (rLayer.RasterClass.Polygon == null)
                                {
                                    continue;
                                }

                                IEnvelope dispEnvelope = this.DisplayTransformation.TransformedBounds(this); //this.Envelope;
                                if (Display.GeometricTransformer != null)
                                {
                                    dispEnvelope = ((IGeometry)Display.GeometricTransformer.InvTransform2D(dispEnvelope)).Envelope;
                                }

                                if (gView.Framework.SpatialAlgorithms.Algorithm.IntersectBox(rLayer.RasterClass.Polygon, dispEnvelope))
                                {
                                    if (rLayer.Class is IParentRasterLayer)
                                    {
                                        if (cancelTracker.Continue)
                                        {
                                            DrawingLayer?.BeginInvoke(layer.Title, new AsyncCallback(AsyncInvoke.RunAndForget), null);
                                        }

                                        await DrawRasterParentLayer((IParentRasterLayer)rLayer.Class, cancelTracker, rLayer);
                                    }
                                    else
                                    {
                                        RenderRasterLayer rlt = new RenderRasterLayer(this, rLayer, rLayer, cancelTracker);

                                        if (cancelTracker.Continue)
                                        {
                                            DrawingLayer?.BeginInvoke(layer.Title, new AsyncCallback(AsyncInvoke.RunAndForget), null);
                                        }

                                        await rlt.Render();
                                    }
                                }
                            }
                            // Andere Layer (zB IRasterLayer)

                            _original.FireDrawingLayerFinished(new gView.Framework.system.TimeEvent("Drawing: " + layer.Title, startTime, DateTime.Now, fCounter.Counter));

                            FireRefreshMapView(1000);
                        }
                        #endregion

                        #region Label Features

                        if (labelLayers.Count != 0)
                        {
                            StreamImage(ref _msGeometry, _bitmap);
                            foreach (IFeatureLayer fLayer in labelLayers)
                            {
                                this.SetGeotransformer(fLayer, geoTransformer);

                                FeatureCounter fCounter  = new FeatureCounter();
                                DateTime       startTime = DateTime.Now;

                                RenderLabel rlt = new RenderLabel(this, fLayer, cancelTracker, fCounter);

                                if (cancelTracker.Continue)
                                {
                                    DrawingLayer?.BeginInvoke(fLayer.Title, new AsyncCallback(AsyncInvoke.RunAndForget), null);
                                }

                                await rlt.Render();

                                _original.FireDrawingLayerFinished(new gView.Framework.system.TimeEvent("Labelling: " + fLayer.Title, startTime, DateTime.Now, fCounter.Counter));
                            }

                            DrawStream(_canvas, _msGeometry);
                        }

                        if (!printerMap)
                        {
                            LabelEngine.Draw(this.Display, cancelTracker);
                        }

                        LabelEngine.Release();

                        #endregion

                        #region Waiting for Webservices

                        if (cancelTracker.Continue)
                        {
                            if (webServices != null && webServices.Count != 0)
                            {
                                DrawingLayer?.BeginInvoke("...Waiting for WebServices...", new AsyncCallback(AsyncInvoke.RunAndForget), null);
                            }

                            while (m_imageMerger.Count < m_imageMerger.max)
                            {
                                await Task.Delay(100);
                            }
                        }
                        if (_drawScaleBar)
                        {
                            m_imageMerger.mapScale = this.mapScale;
                            m_imageMerger.dpi      = this.dpi;
                        }
                        if (m_imageMerger.Count > 0)
                        {
                            var clonedBitmap = _bitmap.Clone(GraphicsEngine.PixelFormat.Rgba32);
                            clonedBitmap.MakeTransparent(_backgroundColor);
                            m_imageMerger.Add(new GeorefBitmap(clonedBitmap), 999);

                            if (!m_imageMerger.Merge(_bitmap, this.Display) &&
                                (this is IServiceMap) &&
                                ((IServiceMap)this).MapServer != null)
                            {
                                await((IServiceMap)this).MapServer.LogAsync(
                                    this.Name,
                                    "Image Merger:",
                                    loggingMethod.error,
                                    m_imageMerger.LastErrorMessage);
                            }
                            m_imageMerger.Clear();
                        }

                        StreamImage(ref _msGeometry, _bitmap);

                        #endregion
                    }
                    #endregion

                    #region Draw Selection

                    if (Bit.Has(phase, DrawPhase.Selection))
                    {
                        if (phase != DrawPhase.All)
                        {
                            DrawStream(_canvas, _msGeometry);
                        }

                        foreach (IDatasetElement layer in this.MapElements)
                        {
                            if (!cancelTracker.Continue)
                            {
                                break;
                            }

                            if (!(layer is ILayer))
                            {
                                continue;
                            }

                            if (layer is IFeatureLayer &&
                                layer is IFeatureSelection &&
                                ((IFeatureSelection)layer).SelectionSet != null &&
                                ((IFeatureSelection)layer).SelectionSet.Count > 0)
                            {
                                SetGeotransformer((ILayer)layer, geoTransformer);
                                await RenderSelection(layer as IFeatureLayer, cancelTracker);
                            } // Andere Layer (zB IRasterLayer)
                            else if (layer is IWebServiceLayer)
                            {
                                IWebServiceLayer wLayer = (IWebServiceLayer)layer;
                                if (wLayer.WebServiceClass == null)
                                {
                                    continue;
                                }

                                foreach (IWebServiceTheme theme in wLayer.WebServiceClass.Themes)
                                {
                                    if (theme is IFeatureLayer &&
                                        theme.SelectionRenderer != null &&
                                        theme is IFeatureSelection &&
                                        ((IFeatureSelection)theme).SelectionSet != null &&
                                        ((IFeatureSelection)theme).SelectionSet.Count > 0)
                                    {
                                        SetGeotransformer(theme, geoTransformer);
                                        await RenderSelection(theme as IFeatureLayer, cancelTracker);
                                    }
                                }
                            }
                        }

                        StreamImage(ref _msSelection, _bitmap);
                    }

                    #endregion

                    #region Graphics

                    if (Bit.Has(phase, DrawPhase.Graphics))
                    //if (phase == DrawPhase.All || phase == DrawPhase.Graphics)
                    {
                        if (phase != DrawPhase.All)
                        {
                            DrawStream(_canvas, (_msSelection != null) ? _msSelection : _msGeometry);
                        }

                        foreach (IGraphicElement grElement in Display.GraphicsContainer.Elements)
                        {
                            grElement.Draw(Display);
                        }
                        foreach (IGraphicElement grElement in Display.GraphicsContainer.SelectedElements)
                        {
                            if (grElement is IGraphicElement2)
                            {
                                if (((IGraphicElement2)grElement).Ghost != null)
                                {
                                    ((IGraphicElement2)grElement).Ghost.Draw(Display);
                                }
                                ((IGraphicElement2)grElement).DrawGrabbers(Display);
                            }
                        }
                    }

                    #endregion

                    #region Cleanup

                    if (geoTransformer != null)
                    {
                        this.GeometricTransformer = null;
                        geoTransformer.Release();
                        geoTransformer = null;
                    }

                    #endregion

                    #region Send Events

                    // Überprüfen, ob sich Extent seit dem letztem Zeichnen geändert hat...
                    if (cancelTracker.Continue)
                    {
                        if (_lastRenderExtent == null)
                        {
                            _lastRenderExtent = new Envelope();
                        }

                        if (NewExtentRendered != null)
                        {
                            if (!_lastRenderExtent.Equals(Display.Envelope))
                            {
                                NewExtentRendered(this, Display.Envelope);
                            }
                        }
                        _lastRenderExtent.minx = Display.Envelope.minx;
                        _lastRenderExtent.miny = Display.Envelope.miny;
                        _lastRenderExtent.maxx = Display.Envelope.maxx;
                        _lastRenderExtent.maxy = Display.Envelope.maxy;
                    }

                    #endregion

                    return(true);
                }
            }
            catch (Exception ex)
            {
                _lastException = ex;
                AddRequestException(ex);
                //System.Windows.Forms.MessageBox.Show(ex.Message+"\n"+ex.InnerException+"\n"+ex.Source);
                return(false);
            }
            finally
            {
                AppendRequestExceptionsToImage();

                if (!printerMap)
                {
                    if (_canvas != null)
                    {
                        _canvas.Dispose();
                    }

                    _canvas = null;
                }

                this.IsRefreshing = false;
            }
        }
 public OptionsLayer(DrawingLayer layer)
 {
     CopyFromLayer(layer);
 }
 abstract public void InitializeFromModel(UnitPoint point, DrawingLayer layer, ISnapPoint snap);
 public void CopyToLayer(DrawingLayer layer)
 {
     layer.Copy(m_layer, false);
 }
Beispiel #37
0
 public override void InitializeFromModel(UnitPoint point, DrawingLayer layer, ISnapPoint snap)
 {
     P1 = P2 = point;
     Width = layer.Width;
     Color = layer.Color;
     Selected = true;
 }
Beispiel #38
0
 internal DrawingLayerBrush(DrawingLayer drawingLayer)
 {
     m_drawingLayer = drawingLayer;
     m_internalBitmapBrush = new SlimDX.Direct2D.BitmapBrush(drawingLayer.D2DRenderTarget.InternalRenderTarget, 
                                                             drawingLayer.D2DRenderTarget.InternalBitmap);
 }
Beispiel #39
0
 public override void InitializeFromModel(UnitPoint point, DrawingLayer layer, ISnapPoint snap)
 {
     FromPoint  = StartPoint = EndPoint = ToPoint = point;
     int count = 1;
     foreach (IDrawObject i in layer.Objects) if (i.GetType() == this.GetType()) count++;
     foreach (Property p in properties) if (p.name == "name" && p.value == "") p.value = this.Id + count;
     Width = layer.Width;
     Color = layer.Color;
     Selected = true;
 }
Beispiel #40
0
 abstract public void InitializeFromModel(UnitPoint point, DrawingLayer layer, ISnapPoint snap);
Beispiel #41
0
 public DrawingContext GetLayer(DrawingLayer layer) => contexts[(int)layer];
Beispiel #42
0
 /// <summary>
 /// 从数据集合中初始化线条并设置垂线快照,正切快照
 /// </summary>
 /// <param name="point"></param>
 /// <param name="layer"></param>
 /// <param name="snap"></param>
 public override void InitializeFromModel(UnitPoint point, DrawingLayer layer, ISnapPoint snap)
 {
     base.InitializeFromModel(point, layer, snap);
     m_perSnap = snap as PerpendicularSnapPoint;
     m_tanSnap = snap as TangentSnapPoint;
 }
Beispiel #43
0
        public void CopyFromDrawingLayer(DrawingLayer drawingLayer)
        {
            if(!drawingLayer.EnableImageCopy)
                throw new Exception("EnableImageCopy must be set to true in order to copy from the DrawingLayer");

            var device = m_directCanvasFactory.DeviceContext.Device;

            var stagingTexture = drawingLayer.SystemMemoryTexture;

            /* Copies our GPU texture to our system memory texture.  This does happen
             * asyncronously UNLESS you call map, which we do afterwards :) */
            device.CopyResource(drawingLayer.RenderTargetTexture.InternalTexture2D,
                                stagingTexture.InternalTexture2D);

            /* Map the texture, so we get an exclusive lock on the pixels */
            var dataRect = stagingTexture.InternalTexture2D.Map(0, MapMode.Read, MapFlags.None);

            /* We lock our image class so we have access to the pixel buffer */
            var imgData = Lock(ImageLock.Write);
            
            CopyTextureDataToImage(imgData, dataRect);

            Unlock(imgData);

            stagingTexture.InternalTexture2D.Unmap(0);
        }