Exemplo n.º 1
0
        public override void Execute()
        {
            ILayoutViewer viewer = _smartSession.SmartWindowManager.ActiveViewer as ILayoutViewer;

            if (viewer == null)
            {
                return;
            }
            if (viewer.LayoutHost == null)
            {
                return;
            }
            ILayoutRuntime runTime = viewer.LayoutHost.LayoutRuntime;

            if (runTime == null)
            {
                return;
            }
            IElement[] elements = runTime.Selection;
            if (elements == null || elements.Length == 0)
            {
                return;
            }
            TryRefreshLayerManager();
        }
Exemplo n.º 2
0
 public void Dispose()
 {
     _sizeChangedHandler    = null;
     _onElementIsDragDroped = null;
     RemoveEvents();
     if (_selectedEditBoxManager != null)
     {
         (_selectedEditBoxManager as SelectedEditBoxManager).Dispose();
         _selectedEditBoxManager = null;
     }
     if (_layout != null)
     {
         _layout.Dispose();
         _layout = null;
     }
     if (_template != null)
     {
         _template.Dispose();
         _template = null;
     }
     if (_drawArgs != null)
     {
         _drawArgs.Reset(null);
         _drawArgs = null;
     }
     if (_layoutRuntime != null)
     {
         _layoutRuntime.Dispose();
         _layoutRuntime = null;
     }
 }
Exemplo n.º 3
0
        private int GetBorderSizeByTemplate(ILayoutRuntime runtime, ILayoutTemplate temp)
        {
            if (temp == null)
            {
                return(0);
            }
            ILayout layout = temp.Layout;

            if (layout == null)
            {
                return(0);
            }
            List <IElement> eles = layout.Elements;

            if (layout.GetBorder() == null)
            {
                return(0);
            }
            SizeF size = layout.GetBorder().Size;

            if (size == SizeF.Empty)
            {
                return(0);
            }
            float w = size.Width;
            float h = size.Height;

            runtime.Layout2Pixel(ref w, ref h);
            return(Math.Max((int)w, (int)h));
        }
Exemplo n.º 4
0
        private void AddElementCustom()
        {
            if (_session.SmartWindowManager.ActiveCanvasViewer == null)
            {
                return;
            }
            ILayoutViewer viewer = _session.SmartWindowManager.ActiveCanvasViewer as ILayoutViewer;

            if (viewer == null)
            {
                return;
            }
            ILayoutHost host = viewer.LayoutHost;

            if (host == null)
            {
                return;
            }
            ILayoutRuntime runtime = host.LayoutRuntime;

            if (runtime == null)
            {
                return;
            }
            IElement[] eles = runtime.Selection;
            if (eles == null || eles.Length == 0)
            {
                return;
            }
            if (_eleList == null)
            {
                return;
            }
            _eleList.CustomElements = eles;
        }
Exemplo n.º 5
0
        public override void Render(object sender, IDrawArgs drawArgs)
        {
            Graphics g = drawArgs.Graphics as Graphics;

            if (g == null)
            {
                return;
            }
            if (_parts == null || _parts.Length == 0)
            {
                return;
            }
            ILayoutRuntime runtime = sender as ILayoutRuntime;

            if (runtime == null)
            {
                return;
            }
            float s = GetDataFrameScale(runtime);

            if (s > 0)
            {
                _scale = s;
            }
            if (float.IsNaN(_scale) || _scale < float.Epsilon)
            {
                return;
            }
            BeginRotate(drawArgs);
            CreatBitmap(drawArgs);
            if (_scaleBarBmpCache == null)
            {
                return;
            }
            try
            {
                float x = _location.X, y = _location.Y;
                drawArgs.Runtime.Layout2Screen(ref x, ref y);
                float scale     = runtime.Scale;
                int   newWidth  = (int)(_size.Width * scale + 0.1f);
                int   newHeight = (int)(_size.Height * scale + 0.1f);
                if (newWidth < 1 || newHeight < 1 || newWidth > 10000 || newHeight > 10000)
                {
                    return;
                }
                using (Bitmap bm = new Bitmap((int)_size.Width, (int)_size.Height))
                {
                    using (Graphics gsp = Graphics.FromImage(bm))
                    {
                        gsp.DrawImage(_scaleBarBmpCache, new Rectangle(0, 0, bm.Width, bm.Height));
                    }
                    g.DrawImage(bm, x, y, newWidth, newHeight);
                }
            }
            finally
            {
                EndRotate(drawArgs);
            }
        }
Exemplo n.º 6
0
 private void TryAttachSelectedEditBox(object sender)
 {
     _runtime = sender as ILayoutRuntime;
     if (_isSelected && this is ISizableElement)
     {
         _runtime.SelectedEditBoxManager.Attach(this as ISizableElement);
     }
 }
Exemplo n.º 7
0
        public void Render(object sender, IDrawArgs drawArgs)
        {
            if (_anchorRect.IsEmpty || _element == null)
            {
                return;
            }
            Graphics      g  = drawArgs.Graphics as Graphics;
            SmoothingMode sm = g.SmoothingMode;

            g.SmoothingMode = SmoothingMode.HighQuality;
            try
            {
                ILayoutRuntime runtime = (sender as ILayoutHost).LayoutRuntime;
                float          x1 = _anchorRect.Left, y1 = _anchorRect.Top;
                float          x2 = _anchorRect.Right, y2 = _anchorRect.Bottom;
                runtime.Layout2Screen(ref x1, ref y1);
                runtime.Layout2Screen(ref x2, ref y2);
                _anchorRect.Location = new PointF(x1, y1);
                _anchorRect.Width    = Math.Abs(x2 - x1);
                _anchorRect.Height   = Math.Abs(y2 - y1);
                g.DrawRectangle(SELECTED_BOX_PEN, _anchorRect.X, _anchorRect.Y, _anchorRect.Width, _anchorRect.Height);
                //
                UpdateAnchorPoints(_anchorRect, runtime.Scale);
                //
                for (int i = 0; i < 8; i++)
                {
                    g.FillRectangle(SELECT_BOX_BRUSH, _anchorPointRects[i].X, _anchorPointRects[i].Y, _anchorPointRects[i].Width, _anchorPointRects[i].Height);
                    g.DrawRectangle(Pens.Black, _anchorPointRects[i].X, _anchorPointRects[i].Y, _anchorPointRects[i].Width, _anchorPointRects[i].Height);
                }
                //draw pin
                if (!(_element is IDataFrame))
                {
                    using (Matrix m = g.Transform.Clone())
                    {
                        PointF cpt = new PointF((_anchorRect.Left + _anchorRect.Right) / 2f, (_anchorRect.Top + _anchorRect.Bottom) / 2f);
                        m.RotateAt(_element.Angle, cpt);
                        Matrix oldM = g.Transform;
                        g.Transform = m;
                        g.FillPath(Brushes.Yellow, _pinBounds);
                        g.DrawPath(Pens.Blue, _pinBounds);
                        g.DrawLine(SELECTED_BOX_PEN,
                                   _anchorRect.Left + _anchorRect.Width / 2f,
                                   _pinPoint.Y + PIN_RADIUS,
                                   _pinPoint.X,
                                   _pinPoint.Y + PIN_RADIUS);
                        g.Transform = oldM;
                    }
                }
            }
            finally
            {
                g.SmoothingMode = sm;
            }
        }
Exemplo n.º 8
0
        public override void Render(object sender, IDrawArgs drawArgs)
        {
            Graphics g = drawArgs.Graphics as Graphics;

            if (g == null)
            {
                return;
            }
            ILayoutRuntime runtime = sender as ILayoutRuntime;

            if (runtime == null)
            {
                return;
            }
            BeginRotate(drawArgs);
            //尺寸改变时才重新绘制
            if (_preSize != _size)
            {
                _northArrowBp = GetNorthArrowBitmap(drawArgs);
            }
            if (_northArrowBp == null)
            {
                return;
            }
            try
            {
                float x = _location.X, y = _location.Y, w = _size.Width, h = _size.Height;
                drawArgs.Runtime.Layout2Screen(ref x, ref y);
                drawArgs.Runtime.Layout2Screen(ref w);
                drawArgs.Runtime.Layout2Screen(ref h);
                float scale     = runtime.Scale;
                int   newWidth  = (int)(_size.Width * scale + 0.1f);
                int   newHeight = (int)(_size.Height * scale + 0.1f);
                if (newWidth < 1 || newHeight < 1 || newWidth > 10000 || newHeight > 10000)
                {
                    return;
                }
                x += 0.5f;
                y += 0.5f;
                using (Bitmap bm = new Bitmap(newWidth, newHeight))
                {
                    using (Graphics gsp = Graphics.FromImage(bm))
                    {
                        gsp.DrawImage(_northArrowBp, new Rectangle(0, 0, bm.Width, bm.Height));
                    }
                    g.DrawImage(bm, (int)x, (int)y);
                }
            }
            finally
            {
                EndRotate(drawArgs);
            }
        }
Exemplo n.º 9
0
 public override void Render(object sender, IDrawArgs drawArgs)
 {
     try
     {
         Graphics g = drawArgs.Graphics as Graphics;
         if (g == null)
         {
             return;
         }
         ILayoutRuntime runtime = sender as ILayoutRuntime;
         if (runtime == null)
         {
             return;
         }
         BeginRotate(drawArgs);
         if (_preSize != _size)
         {
             CreatBitmap(drawArgs);
         }
         if (_bmp == null)
         {
             return;
         }
         try
         {
             float x = _location.X, y = _location.Y;
             drawArgs.Runtime.Layout2Screen(ref x, ref y);
             float scale     = runtime.Scale;
             int   newWidth  = (int)(_size.Width * scale + 0.1f);
             int   newHeight = (int)(_size.Height * scale + 0.1f);
             if (newWidth < 1 || newHeight < 1)
             {
                 return;
             }
             using (Bitmap bm = new Bitmap(newWidth, newHeight))
             {
                 using (Graphics gsp = Graphics.FromImage(bm))
                 {
                     gsp.DrawImage(_bmp, new Rectangle(0, 0, bm.Width, bm.Height));
                 }
                 g.DrawImage(bm, x, y);
             }
         }
         finally
         {
             EndRotate(drawArgs);
         }
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.Message);
     }
 }
Exemplo n.º 10
0
 public DataFrameDataProvider(ISizableElement dataFrame, ILayoutRuntime runtime,
                              bool isUseDefaultBackgroudLayer, Color landColor, Color seaColor, string[] interestRegions)
 {
     InitializeComponent();
     _dataFrame = dataFrame;
     _runtime   = runtime;
     _isUseDefaultBackgroudLayer = isUseDefaultBackgroudLayer;
     _landColor       = landColor;
     _seaColor        = seaColor;
     _interestRegions = interestRegions;
     SizeChanged     += new EventHandler(DataFrameDataProvider_SizeChanged);
     TryReCreateCanvasHost(_isUseDefaultBackgroudLayer);
 }
Exemplo n.º 11
0
        private float GetDataFrameScale(ILayoutRuntime runtime)
        {
            ILayoutHost host = runtime.GetHost();

            if (host == null)
            {
                return(-1);
            }
            if (host.ActiveDataFrame == null)
            {
                return(-1);
            }
            return(host.ActiveDataFrame.LayoutScale);
        }
Exemplo n.º 12
0
        private void 解锁_Click(object sender, EventArgs e)
        {
            ILayoutRuntime runtime = _host.LayoutRuntime;

            if (runtime.Selection == null || runtime.Selection.Length == 0)
            {
                return;
            }
            IElement[] elements = runtime.Selection;
            foreach (IElement element in elements)
            {
                element.IsLocked = false;
            }
            _host.Render();
        }
Exemplo n.º 13
0
        public override void Render(object sender, IDrawArgs drawArgs)
        {
            Graphics g = drawArgs.Graphics as Graphics;

            if (g == null)
            {
                return;
            }
            ILayoutRuntime runtime = sender as ILayoutRuntime;

            if (runtime == null)
            {
                return;
            }
            BeginRotate(drawArgs);
            if (_preSize != _size)
            {
                CreatBitmap(drawArgs, g);
            }
            if (_legendBmp == null)
            {
                return;
            }
            try
            {
                float x = _location.X, y = _location.Y;
                drawArgs.Runtime.Layout2Screen(ref x, ref y);
                float scale     = runtime.Scale;
                float newWidth  = _size.Width * scale + 0.1f;
                float newHeight = _size.Height * scale + 0.1f;
                if (newWidth < 1 || newHeight < 1 || newWidth > 10000 || newHeight > 10000)
                {
                    return;
                }
                using (Bitmap bm = new Bitmap((int)newWidth, (int)newHeight))
                {
                    using (Graphics g1 = Graphics.FromImage(bm))
                    {
                        g1.DrawImage(_legendBmp, 0, 0, bm.Width, bm.Height);
                    }
                    g.DrawImage(bm, (int)x, (int)y);
                }
            }
            finally
            {
                EndRotate(drawArgs);
            }
        }
Exemplo n.º 14
0
        public override void Execute()
        {
            ILayoutViewer host = _smartSession.SmartWindowManager.ActiveViewer as ILayoutViewer;

            if (host == null)
            {
                return;
            }
            ILayoutRuntime runtime = host.LayoutHost.LayoutRuntime;

            if (runtime.Selection != null)
            {
                runtime.ClearSelection();
            }
            host.LayoutHost.Render();
        }
Exemplo n.º 15
0
 public void Update(ILayoutRuntime layoutRuntime)
 {
     _boxes.Clear();
     IElement[] selection = layoutRuntime.Selection;
     if (selection == null)
     {
         return;
     }
     foreach (IElement ele in selection)
     {
         if (ele.IsSelected && ele is ISizableElement)
         {
             _boxes.Add(ele as ISizableElement, new SelectedEditBox(ele as ISizableElement));
         }
     }
 }
Exemplo n.º 16
0
        private void HandleDoubleClick(ILayoutHost host, CanvasEventArgs e)
        {
            if (host == null)
            {
                return;
            }
            ILayoutRuntime runtime = host.LayoutRuntime;

            if (runtime == null)
            {
                return;
            }
            IElement[] eles = runtime.Hit(e.LayoutX, e.LayoutY);
            if (eles == null || eles.Length == 0)
            {
                return;
            }
            _scale = runtime.Scale;
            foreach (IElement ele in eles)
            {
                if (ele is TextElement)
                {
                    if (ele.IsLocked)
                    {
                        continue;
                    }
                    _currentHost    = host;
                    _txtEle         = ele as TextElement;
                    _txtEle.Visible = false;
                    TextBox box = CreatTextbox(host);
                    return;
                }
                else if (ele is MultlineTextElement)
                {
                    if (ele.IsLocked)
                    {
                        continue;
                    }
                    _currentHost = host;
                    CreatMultlineTextbox(host, ele as MultlineTextElement);
                    return;
                }
            }
        }
Exemplo n.º 17
0
 private void Rotate(ILayoutRuntime runtime, float angle)
 {
     if (runtime == null)
     {
         return;
     }
     IElement[] eles = runtime.Selection;
     if (eles == null || eles.Length == 0)
     {
         return;
     }
     foreach (IElement ele in eles)
     {
         if (!(ele is SizableElement))
         {
             continue;
         }
         (ele as SizableElement).Angle = angle;
     }
 }
Exemplo n.º 18
0
        void IDisposable.Dispose()
        {
            if (_canvasHost != null)
            {
                if (_canvasHost as IDisposable != null)
                {
                    (_canvasHost as IDisposable).Dispose();
                }
                _canvasHost.Dispose();
                _canvasHost = null;
            }
            if (_buffer != null)
            {
                _buffer.Dispose();
                _buffer = null;
            }

            _runtime   = null;
            _dataFrame = null;
        }
Exemplo n.º 19
0
        public override void Render(object sender, IDrawArgs drawArgs)
        {
            Graphics g = drawArgs.Graphics as Graphics;

            if (g == null)
            {
                return;
            }
            ILayoutRuntime runtime = sender as ILayoutRuntime;
            float          screenX = _location.X, screenY = _location.Y;

            runtime.Layout2Screen(ref screenX, ref screenY);
            //Pen p = new Pen(Brushes.Black);
            //p.Alignment = System.Drawing.Drawing2D.PenAlignment.Inset;
            //注释掉的语句不起作用,因此为了保证右边和下边的边框能够被导出,特意减了1
            float w = _size.Width, h = _size.Height;

            runtime.Layout2Pixel(ref w, ref h);
            if (DrawArgs.IsExporting)
            {
                if (_backColor != Color.Empty && _brush != null)
                {
                    g.FillRectangle(_brush, screenX, screenY, w * runtime.Scale - 1, h * runtime.Scale - 1);
                }
                if (_isShowBorderLine)
                {
                    g.DrawRectangle(Pens.Black, screenX, screenY, w * runtime.Scale - 1, h * runtime.Scale - 1);
                }
            }
            else
            {
                if (_backColor != Color.Empty && _brush != null)
                {
                    g.FillRectangle(_brush, screenX, screenY, w * runtime.Scale - 1, h * runtime.Scale - 1);
                }
                if (_isShowBorderLine)
                {
                    g.DrawRectangle(Pens.Black, screenX, screenY, w * runtime.Scale, h * runtime.Scale);
                }
            }
        }
Exemplo n.º 20
0
        public override void Execute()
        {
            ILayoutViewer layout = _smartSession.SmartWindowManager.ActiveViewer as ILayoutViewer;

            if (layout == null)
            {
                return;
            }
            ILayoutRuntime runtime = layout.LayoutHost.LayoutRuntime;

            if (runtime.LockedElements == null || runtime.LockedElements.Length == 0)
            {
                return;
            }
            IElement[] eles = runtime.LockedElements;
            foreach (IElement element in eles)
            {
                element.IsLocked = false;
            }
            layout.LayoutHost.Render();
        }
Exemplo n.º 21
0
        protected virtual void BeginRotate(IDrawArgs drawArgs)
        {
            if (Math.Abs(_angle) < float.Epsilon)
            {
                return;
            }
            while (_angle > 360)
            {
                _angle -= 360;
            }
            ;
            while (_angle < 0)
            {
                _angle += 360;
            }
            ;
            Graphics       g       = drawArgs.Graphics as Graphics;
            ILayoutRuntime runtime = drawArgs.Runtime;

setAgleLine:
            if (_matrix != null)
            {
                _matrix.Reset();
                float x = _location.X + _size.Width / 2;
                float y = _location.Y + _size.Height / 2;
                runtime.Layout2Screen(ref x, ref y);
                _matrix.RotateAt(_angle, new PointF(x, y));
            }
            else
            {
                _matrix = new Matrix();
                goto setAgleLine;
            }
            _oldMatrix = g.Transform;
            Matrix c = _matrix.Clone();

            c.Multiply(_oldMatrix, MatrixOrder.Append);
            g.Transform = c;
        }
Exemplo n.º 22
0
        public override void Execute()
        {
            ILayoutViewer viewer = _smartSession.SmartWindowManager.ActiveViewer as ILayoutViewer;

            if (viewer == null)
            {
                return;
            }
            ILayoutHost host = viewer.LayoutHost;

            if (host == null)
            {
                return;
            }
            ILayoutRuntime runtime = host.LayoutRuntime;

            if (runtime == null)
            {
                return;
            }
            float w = 0, h = 0;

            using (OpenFileDialog dlg = new OpenFileDialog())
            {
                dlg.Filter = "JPEG(*.jpg)|*.jpg|BMP(*.bmp)|*.bmp|PNG(*.png)|*.png";
                if (dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    PictureElement pic = new PictureElement(dlg.FileName);
                    w = pic.Size.Width;
                    h = pic.Size.Height;
                    runtime.Pixel2Layout(ref w, ref h);
                    pic.Size = new System.Drawing.SizeF(w, h);
                    viewer.LayoutHost.LayoutRuntime.Layout.Elements.Add(pic);
                    viewer.LayoutHost.Render();
                }
            }
            TryRefreshLayerManager();
        }
Exemplo n.º 23
0
        public void Apply(ILayoutRuntime runtime, int anchorIndex, PointF bPoint, PointF ePoint)
        {
            float offsetX = ePoint.X - bPoint.X;
            float offsetY = ePoint.Y - bPoint.Y;

            //约束长宽比
            //Console.WriteLine(anchorIndex.ToString());
            //Console.WriteLine("OffsetY:" + offsetY.ToString());
            if (Control.ModifierKeys == Keys.Shift)
            {
                if (anchorIndex == 0 || anchorIndex == 2 || anchorIndex == 4 || anchorIndex == 6)
                {
                    float factor = Math.Abs(offsetX / _element.Size.Width);
                    if (offsetX < 0 && anchorIndex == 4)
                    {
                        factor *= -1f;
                    }
                    else if (offsetX > 0 && anchorIndex == 6)
                    {
                        factor *= -1f;
                    }
                    else if (offsetX < 0 && anchorIndex == 0)
                    {
                        factor *= -1f;
                    }
                    else if (offsetX > 0 && anchorIndex == 2)
                    {
                        factor *= -1f;
                    }
                    offsetY = factor * _element.Size.Height;
                }
            }
            switch (anchorIndex)
            {
            case 0:    //up-left
                _element.ApplyLocation(offsetX, offsetY);
                _element.ApplySize(-offsetX, -offsetY);
                break;

            case 4:    //right-down
                _element.ApplySize(offsetX, offsetY);
                break;

            case 1:    //up
                _element.ApplyLocation(0, offsetY);
                _element.ApplySize(0, -offsetY);
                break;

            case 5:    //down
                _element.ApplySize(0, offsetY);
                break;

            case 3:    //right
                _element.ApplySize(offsetX, 0);
                break;

            case 7:    //left
                _element.ApplyLocation(offsetX, 0);
                _element.ApplySize(-offsetX, 0);
                break;

            case 2:    //right-up
                _element.ApplyLocation(0, offsetY);
                _element.ApplySize(offsetX, -offsetY);
                break;

            case 6:    //left-down
                _element.ApplyLocation(offsetX, 0);
                _element.ApplySize(-offsetX, offsetY);
                break;

            case 8:    //rotate
                if (offsetY != 0)
                {
                    PointF cpt = new PointF((_anchorRect.Left + _anchorRect.Right) / 2f, (_anchorRect.Top + _anchorRect.Bottom) / 2f);
                    float  x   = ePoint.X;
                    float  y   = ePoint.Y;
                    runtime.Layout2Screen(ref x, ref y);
                    float angle = MathHelper.GetAngle(cpt, new PointF(x, y));
                    //Console.WriteLine(angle.ToString());
                    _element.ApplyRotate(angle);
                }
                break;
            }
        }
Exemplo n.º 24
0
        private void CreateLayoutRuntime()
        {
            ILayout layout = LoadLayout();

            _layoutRuntime = new LayoutRuntime(layout, this);
        }
Exemplo n.º 25
0
 public DrawArgs(ILayoutRuntime runtime)
 {
     _runtime = runtime;
 }