Beispiel #1
0
        private unsafe void DrawContour(IDrawArgs drawArgs, ContourLine cntLine, ContourClass cntClass, ICanvas canvas)
        {
            if (!cntClass.IsDisplay)
            {
                return;
            }
            ICoordinateTransform tran = canvas.CoordTransform;
            int nCount = cntLine.Count;

            PointF[] pts       = new PointF[nCount];
            GCHandle dstHandle = GCHandle.Alloc(pts, GCHandleType.Pinned);
            GCHandle srcHandle = GCHandle.Alloc(cntLine.Points, GCHandleType.Pinned);

            try
            {
                MemoryCopy(dstHandle.AddrOfPinnedObject(), srcHandle.AddrOfPinnedObject(), nCount << _pointfSize); // nCount * sizeof(PointF)
                QuickTransform quickTran = drawArgs.QuickTransformArgs;
                fixed(PointF *ptr0 = pts)
                {
                    PointF *ptr = ptr0;

                    for (int i = 0; i < nCount; i++, ptr++)
                    {
                        quickTran.Transform(ptr);
                    }
                }
                Graphics g = drawArgs.Graphics as Graphics;
                //
                if (_isUseCurveRender)
                {
                    g.DrawCurve(cntClass.Pen, pts, _tension);
                }
                else
                {
                    _grahpicPath.Reset();
                    _grahpicPath.AddLines(pts);
                    g.DrawPath(cntClass.Pen, _grahpicPath);
                }
                //
                if (_isLabel)
                {
                    if (_isCheckConflicting)
                    {
                        if (_conflictor.IsConflicted(pts[0], cntClass.LabelBuffer.Size))
                        {
                            return;
                        }
                        _conflictor.HoldPosition(pts[0], cntClass.LabelBuffer.Size);
                    }
                    g.DrawImageUnscaled(cntClass.LabelBuffer, (int)pts[0].X, (int)pts[0].Y);
                }
            }
            finally
            {
                dstHandle.Free();
                srcHandle.Free();
            }
        }
Beispiel #2
0
        public void Render(object sender, IDrawArgs drawArgs)
        {
            if (_cntLines == null || _cntLines.Length == 0 || _contourClassItems == null || _contourClassItems.Length == 0)
            {
                return;
            }
            if (_canvas == null)
            {
                _canvas                    = sender as ICanvas;
                _canvasSizeChanged         = new EventHandler(Container_SizeChanged);
                _canvas.OnEnvelopeChanged += _canvasSizeChanged;
                _conflictor                = new PixelConflictor(_canvas.Container.Size);
            }
            CoordEnvelope evp = _canvas.CurrentEnvelope;

            _crtCanvasEnvelope = new ContourLine.ContourEnvelope((float)evp.MinX, (float)evp.MaxX, (float)evp.MinY, (float)evp.MaxY);
            TryUpdateLabelBuffers(drawArgs);
            TryProject();
            TrySetSmoothMode(drawArgs);
            TryResetConflictor();
            float minWidth  = MIN_WIDTH * _canvas.ResolutionX;
            float minHeight = MIN_WIDTH * _canvas.ResolutionY;

            ContourLine.ContourEnvelope thisEvp = null;
            int          classIdx = 0;
            ContourClass cntClass = null;

            foreach (ContourLine cntLine in _cntLines)
            {
                if (cntLine == null)
                {
                    continue;
                }
                classIdx = cntLine.ClassIndex;
                cntClass = _contourClassItems[classIdx];
                thisEvp  = cntLine.Envelope;
                //如果不在可视区域则绘制
                if (!_crtCanvasEnvelope.IsInteractived(thisEvp))
                {
                    continue;
                }
                //如果在当前比例尺下太小则不显示
                if (thisEvp.Width > minWidth || thisEvp.Height > minHeight)
                {
                    DrawContour(drawArgs, cntLine, cntClass, _canvas);
                }
            }
        }
Beispiel #3
0
        protected override object CreateAndFillObject(XElement propertyXml)
        {
            List <ContourClass> ccs = new List <ContourClass>();
            var itemElements        = propertyXml.Elements("ContourClass");

            foreach (XElement itemElement in itemElements)
            {
                double   contourValue = AttToDouble(itemElement, "contourvalue");
                bool     isdisplay    = AttToBool(itemElement, "isdisplay");
                float    linewidth    = AttToFloat(itemElement, "linewidth");
                Color    contourColor = Color.Black;
                XElement cElement     = itemElement.Element("ContourColor");
                if (cElement != null)
                {
                    ColorPropertyConverter c = new ColorPropertyConverter();
                    contourColor = (Color)c.FromXml(cElement);
                }
                ContourClass cc = new ContourClass(contourValue, contourColor, linewidth);
                ccs.Add(cc);
            }
            return(ccs.Count > 0 ? ccs.ToArray() : null);
        }