コード例 #1
0
        /// <summary>
        /// 合并可以合并的线段
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void MergeTestBtn_Click(object sender, RoutedEventArgs e)
        {
            List <Geometry2D> gss   = this.drawingKernel.GeometryShapes;
            List <Line2D>     lines = new List <Line2D>();

            foreach (var g in gss)
            {
                if (g is DrawingKernel.Geometries.Primitives.LineGeometry)
                {
                    DrawingKernel.Geometries.Primitives.LineGeometry line = g as DrawingKernel.Geometries.Primitives.LineGeometry;
                    lines.Add(Line2D.Create(line.Start, line.End));
                }
                if (g.GeometryId == "tp")
                {
                    this.drawingKernel.RemoveGeometryShape(g);
                }
            }

            List <Line2D> mergeLines = GraphicAlgorithm.Merge(lines);

            if (mergeLines != null)
            {
                mergeLines.ForEach(x =>
                {
                    DrawingKernel.Geometries.Primitives.LineGeometry lg = new DrawingKernel.Geometries.Primitives.LineGeometry(x.Start, x.End);
                    lg.PenColor   = KernelProperty.GetRandomColor();
                    lg.GeometryId = "tp";
                    this.drawingKernel.AddShape(lg);
                });
            }
        }
コード例 #2
0
ファイル: DrawingControl.cs プロジェクト: AlbertMin/AlbertCAD
        /// <summary>
        /// 右键按下事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void DrawingControl_MouseRightButtonDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
        {
            //定义当前右键点击事件
            if (RightMenuEvent != null)
            {
                Vector2D p = KernelProperty.PixToMM(e.GetPosition(this));

                if (EAction != null)
                {
                    IntersectPoint catchPoint = GetIntersectPointCatch(p);

                    //设置捕获点
                    if (catchPoint != null)
                    {
                        p = catchPoint.Point;
                    }
                }
                RightMouseEventArgs rmea = new RightMouseEventArgs(EAction, p);
                RightMenuEvent(rmea);
            }
            else
            {
                EAction.Termimal();
            }
        }
コード例 #3
0
        private void ClosetTestBtn2_Click(object sender, RoutedEventArgs e)
        {
            //封闭区域测试
            List <Geometry2D> gss = this.drawingKernel.GeometryShapes;

            List <Line2D> lines = new List <Line2D>();

            //转换图形
            foreach (var g in gss)
            {
                if (g is DrawingKernel.Geometries.Primitives.LineGeometry)
                {
                    DrawingKernel.Geometries.Primitives.LineGeometry line = g as DrawingKernel.Geometries.Primitives.LineGeometry;
                    lines.Add(Line2D.Create(line.Start, line.End));
                }
                if (g.GeometryId == "tp")
                {
                    this.drawingKernel.RemoveGeometryShape(g);
                }
            }
            //查找封闭区域
            List <List <Line2D> > nn = GraphicAlgorithm.ClosedLookup(lines, false, true);

            if (nn != null)
            {
                nn.ForEach(x =>
                {
                    PolygonGeometry pg = new PolygonGeometry();
                    x.ForEach(y => { pg.PPoints.Add(y.Start); });
                    pg.FillColor  = KernelProperty.GetRandomColor();
                    pg.GeometryId = "tp";
                    this.drawingKernel.AddShape(pg);
                });
            }
        }
コード例 #4
0
        /// <summary>
        /// 图形的内缩小
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ElasticityTestBtn_Click(object sender, RoutedEventArgs e)
        {
            List <Geometry2D> gss   = this.drawingKernel.GeometryShapes;
            List <Line2D>     lines = new List <Line2D>();

            foreach (var g in gss)
            {
                if (g is DrawingKernel.Geometries.Primitives.LineGeometry)
                {
                    DrawingKernel.Geometries.Primitives.LineGeometry line = g as DrawingKernel.Geometries.Primitives.LineGeometry;
                    lines.Add(Line2D.Create(line.Start, line.End));
                }
                if (g.GeometryId == "tp")
                {
                    this.drawingKernel.RemoveGeometryShape(g);
                }
            }
            //查找封闭区域
            List <List <Line2D> > nn = GraphicAlgorithm.ClosedLookup(lines, true, true);

            if (nn != null && nn.Count > 0)
            {
                List <Line2D> nt = nn[0];

                List <Line2D> wtn = GraphicAlgorithm.Elastic(nt, -20);

                PolygonGeometry pg = new PolygonGeometry();
                wtn.ForEach(y => { pg.PPoints.Add(y.Start); });
                pg.FillColor  = KernelProperty.GetRandomColor();
                pg.GeometryId = "tp";
                this.drawingKernel.AddShape(pg);
            }
        }
コード例 #5
0
ファイル: ArcGeometry.cs プロジェクト: AlbertMin/AlbertCAD
 /// <summary>
 /// 刷新显示指定的图形元素
 /// </summary>
 public override void Update()
 {
     if (Start != null && Central != null && End == null)
     {
         this.DashStyle = new System.Windows.Media.DashStyle(new double[] { 5, 5 }, 10);
         DrawingContext dc = this.RenderOpen();
         Pen.Freeze();  //冻结画笔,这样能加快绘图速度
         List <Vector2D> vs = new List <Vector2D>()
         {
             Start, Central
         };
         this.Draw(vs);
     }
     else if (Start != null && Central != null && End != null)
     {
         //冻结画笔,这样能加快绘图速度
         DrawingContext dc = this.RenderOpen();
         Pen.Freeze();
         ArcSegment arc = new ArcSegment();
         var        len = this.Central.Distance(this.start);
         arc.IsLargeArc = false;
         arc.Size       = new System.Windows.Size(KernelProperty.MMToPix(len), KernelProperty.MMToPix(len));
         arc.Point      = KernelProperty.MMToPix(this.end);
         PathGeometry         paths = new PathGeometry();
         PathFigureCollection pfc   = new PathFigureCollection();
         PathFigure           pf    = new PathFigure();
         pfc.Add(pf);
         pf.StartPoint = KernelProperty.MMToPix(this.start);
         pf.Segments.Add(arc);
         paths.Figures = pfc;
         dc.DrawGeometry(Brush, Pen, paths);
         dc.Close();
     }
 }
コード例 #6
0
        /// <summary>
        /// 绘制相关的文字信息
        /// </summary>
        /// <param name="dc"></param>
        /// <param name="startToLine"></param>
        private void SeText(DrawingContext dc, Line2D startToLine)
        {
            string   text   = ((int)Math.Round(startToLine.Length)).ToString();
            Vector2D middle = startToLine.MiddlePoint;

            Vector2D dir = startToLine.Direction;
            var      rad = dir.AngleFrom(Vector2D.BasisX);

            var angle = Extension.RadToDeg(rad);

            if (angle > 90 && angle < 270)
            {
                angle = angle + 180;
            }

            var             md = KernelProperty.MMToPix(middle);
            RotateTransform rt = new RotateTransform();

            rt.Angle   = angle;
            rt.CenterX = md.X;
            rt.CenterY = md.Y;
            dc.PushTransform(rt);
            FormattedText ft = new FormattedText(text, new System.Globalization.CultureInfo(0x0804, false), System.Windows.FlowDirection.LeftToRight, new Typeface("微软雅黑"), 14, Brushes.Blue);

            dc.DrawText(ft, md);
            dc.Pop();
        }
コード例 #7
0
        /// <summary>
        /// 开始绘制
        /// </summary>
        /// <param name="gs"></param>
        private void A_DrawStartEvent(ActionEventArgs gs)
        {
            TextGeometry tg = (gs.Geometry2D as TextGeometry);
            var          md = KernelProperty.MMToPix(tg.FontSize);
            Vector2D     nv = Vector2D.Create(tg.Central.X, tg.Central.Y - md / 2);

            this.Tip.SetText("|", nv, 0);
        }
コード例 #8
0
        /// <summary>
        /// 绘制相关的文字信息
        /// </summary>
        /// <param name="dc"></param>
        /// <param name="startToLine"></param>
        private void SeText(DrawingContext dc, Line2D startToLine)
        {
            Vector2D      middle = startToLine.MiddlePoint;
            var           md     = KernelProperty.MMToPix(middle);
            string        text   = ((int)Extension.RadToDeg(Angle)).ToString();
            FormattedText ft     = new FormattedText(text, new System.Globalization.CultureInfo(0x0804, false), System.Windows.FlowDirection.LeftToRight, new Typeface("微软雅黑"), 14, Brushes.Blue);

            dc.DrawText(ft, md);
        }
コード例 #9
0
        /// <summary>
        /// 绘制当前的墙体
        /// </summary>
        /// <param name="points"></param>
        protected override void Draw(List <Vector2D> points)
        {
            if (start != null && end != null)
            {
                var halfThickness = Thickness / 2;

                List <Vector2D> fillPoints = new List <Vector2D>();
                var             start3D    = new Albert.Geometry.Primitives.Vector3D(Start.X, Start.Y, 0);
                var             end3D      = new Albert.Geometry.Primitives.Vector3D(End.X, End.Y, 0);

                Vector3D lineDir = end3D - start3D;

                Vector3D offsetDir = lineDir.Cross(new Vector3D(0, 0, 1)).Normalize();
                Vector3D offv1     = start3D + halfThickness * offsetDir;
                Vector3D offv2     = start3D - halfThickness * offsetDir;
                Vector3D offv3     = end3D - halfThickness * offsetDir;
                Vector3D offv4     = end3D + halfThickness * offsetDir;


                Line2D l5 = Line2D.Create(start, end);


                //钢梁
                fillPoints.Add(TransformUtil.Projection(offv1));
                fillPoints.Add(TransformUtil.Projection(offv2));
                fillPoints.Add(TransformUtil.Projection(offv3));
                fillPoints.Add(TransformUtil.Projection(offv4));
                fillPoints.Add(TransformUtil.Projection(offv4));


                DrawingContext dc = this.RenderOpen();
                Pen.Freeze();  //冻结画笔,这样能加快绘图速度
                PathGeometry paths = new PathGeometry();
                paths.FillRule = FillRule.EvenOdd;
                PathFigureCollection pfc = new PathFigureCollection();
                PathFigure           pf  = new PathFigure();
                pfc.Add(pf);
                pf.StartPoint = KernelProperty.MMToPix(fillPoints[0]);


                for (int i = 0; i < fillPoints.Count; i++)
                {
                    LineSegment ps = new LineSegment();
                    ps.Point = KernelProperty.MMToPix(fillPoints[i]);
                    pf.Segments.Add(ps);
                }


                pf.IsClosed   = true;
                paths.Figures = pfc;
                PenColor      = Colors.Black;
                dc.DrawGeometry(Brush, Pen, paths);
                PenColor = Colors.DeepPink;
                dc.DrawLine(Pen, KernelProperty.MMToPix(l5.Start), KernelProperty.MMToPix(l5.End));
                dc.Close();
            }
        }
コード例 #10
0
ファイル: DrawingControl.cs プロジェクト: AlbertMin/AlbertCAD
 /// <summary>
 /// 拖动控件
 /// </summary>
 /// <param name="p"></param>
 private void DragMoveView(Point?p)
 {
     if (EndPoint != null)
     {
         this.Cursor = CursorGetter.Getter(CursorStyle.Move);
         KernelProperty.PanTo(p.Value, EndPoint.Value);
         this.Update();
     }
     EndPoint = p;
 }
コード例 #11
0
        /// <summary>
        /// 按照点,绘制连续的线段,且没有填充
        /// </summary>
        /// <param name="points"></param>
        /// <param name="color"></param>
        /// <param name="thinkness"></param>
        /// <returns></returns>
        protected virtual void Draw(List <Vector2D> points)
        {
            DrawingContext dc = this.RenderOpen();

            Pen.Freeze();  //冻结画笔,这样能加快绘图速度
            for (int i = 0; i < points.Count - 1; i++)
            {
                dc.DrawLine(Pen, KernelProperty.MMToPix(points[i]), KernelProperty.MMToPix(points[i + 1]));
            }
            dc.Close();
        }
コード例 #12
0
        /// <summary>
        /// 当前直线的绘制功能
        /// </summary>
        /// <param name="vss"></param>
        protected override void Draw(List <Vector2D> points)
        {
            DrawingContext dc = this.RenderOpen();

            //冻结画笔,这样能加快绘图速度
            Pen.Freeze();
            dc.DrawLine(Pen, KernelProperty.MMToPix(points[0]), KernelProperty.MMToPix(points[1]));
            dc.DrawLine(Pen, KernelProperty.MMToPix(points[1]), KernelProperty.MMToPix(points[2]));
            SeText(dc, Line2D.Create(points[1], points[2]));
            dc.DrawLine(Pen, KernelProperty.MMToPix(points[2]), KernelProperty.MMToPix(points[3]));
            dc.Close();
        }
コード例 #13
0
        private void drawRect(DrawingContext dc, Vector2D central)
        {
            var v1 = new Vector2D(central.X - 5 * KernelProperty.PixelToSize, central.Y - 5 * KernelProperty.PixelToSize);
            var v2 = new Vector2D(central.X + 5 * KernelProperty.PixelToSize, central.Y - 5 * KernelProperty.PixelToSize);
            var v3 = new Vector2D(central.X + 5 * KernelProperty.PixelToSize, central.Y + 5 * KernelProperty.PixelToSize);
            var v4 = new Vector2D(central.X - 5 * KernelProperty.PixelToSize, central.Y + 5 * KernelProperty.PixelToSize);

            dc.DrawLine(Pen, KernelProperty.MMToPix(v1), KernelProperty.MMToPix(v2));
            dc.DrawLine(Pen, KernelProperty.MMToPix(v2), KernelProperty.MMToPix(v3));
            dc.DrawLine(Pen, KernelProperty.MMToPix(v3), KernelProperty.MMToPix(v4));
            dc.DrawLine(Pen, KernelProperty.MMToPix(v4), KernelProperty.MMToPix(v1));
        }
コード例 #14
0
 /// <summary>
 /// 开始绘制
 /// </summary>
 /// <param name="ms"></param>
 public override void Update()
 {
     if (start != null && End != null)
     {
         List <Vector2D> points = new List <Vector2D>();
         points.Add(start);
         points.Add(end);
         var xl  = KernelProperty.PixToMM(30);
         var leg = Vector2D.Create(end.X + xl, end.Y);
         points.Add(leg);
         this.Draw(points);
     }
 }
コード例 #15
0
        /// <summary>
        /// 刷新当前的绘制
        /// </summary>
        public override void Update()
        {
            DrawingContext dc = this.RenderOpen();

            Pen.Freeze();  //冻结画笔,这样能加快绘图速度
            this.PenColor  = Colors.Red;
            this.LineWidth = 2;
            for (int i = 0; i < lightLines.Count; i++)
            {
                dc.DrawLine(Pen, KernelProperty.MMToPix(lightLines[i].Start), KernelProperty.MMToPix(lightLines[i].End));
            }
            dc.Close();
        }
コード例 #16
0
        /// <summary>
        /// 绘制圆形,并且填充当前形状
        /// </summary>
        /// <param name="Central"></param>
        /// <param name="RadiusX"></param>
        /// <param name="RadiusY"></param>
        /// <param name="brush"></param>
        protected override void DrawArcFill(Vector2D Central, double RadiusX, double RadiusY)
        {
            DrawingContext dc = this.RenderOpen();

            Pen.Freeze();  //冻结画笔,这样能加快绘图速度
            EllipseGeometry Geometry = new EllipseGeometry();

            Geometry.Center  = KernelProperty.MMToPix(Central);
            Geometry.RadiusX = RadiusX;
            Geometry.RadiusY = RadiusY;
            dc.DrawGeometry(Brush, Pen, Geometry);
            dc.Close();
        }
コード例 #17
0
        /// <summary>
        /// 绘制圆形,且没有填充
        /// </summary>
        /// <param name="points"></param>
        protected virtual void DrawArc(Vector2D Central, double RadiusX, double RadiusY)
        {
            DrawingContext dc = this.RenderOpen();

            Pen.Freeze();  //冻结画笔,这样能加快绘图速度
            EllipseGeometry Geometry = new EllipseGeometry();

            Geometry.Center  = KernelProperty.MMToPix(Central);
            Geometry.RadiusX = KernelProperty.MMToPix(RadiusX);
            Geometry.RadiusY = KernelProperty.MMToPix(RadiusY);
            dc.DrawGeometry(new SolidColorBrush(Colors.Transparent), Pen, Geometry);
            dc.Close();
        }
コード例 #18
0
        /// <summary>
        /// 刷新当前的绘制
        /// </summary>
        public override void Update()
        {
            DrawingContext dc = this.RenderOpen();

            Pen.Freeze();  //冻结画笔,这样能加快绘图速度
            this.DashStyle = new System.Windows.Media.DashStyle(new double[] { 5, 5 }, 10);
            this.PenColor  = Colors.Red;
            this.LineWidth = 5;
            for (int i = 0; i < lightLines.Count; i++)
            {
                dc.DrawLine(Pen, KernelProperty.MMToPix(lightLines[i].Start), KernelProperty.MMToPix(lightLines[i].End));
            }
            dc.Close();
        }
コード例 #19
0
ファイル: TextGeometry.cs プロジェクト: AlbertMin/AlbertCAD
 protected override void Draw(List <Vector2D> points)
 {
     if (this.Text != "")
     {
         DrawingContext  dc = this.RenderOpen();
         RotateTransform rt = new RotateTransform();
         var             md = KernelProperty.MMToPix(Central);
         rt.CenterX = md.X;
         rt.CenterY = md.Y;
         dc.PushTransform(rt);
         FormattedText ft = new FormattedText(text, new System.Globalization.CultureInfo(0x0804, false), System.Windows.FlowDirection.LeftToRight, new Typeface("宋体"), FontSize, new SolidColorBrush(PenColor));
         dc.DrawText(ft, md);
         dc.Close();
     }
 }
コード例 #20
0
        /// <summary>
        /// 按照点,绘制连续的线段,且没有填充
        /// </summary>
        /// <param name="points"></param>
        /// <param name="color"></param>
        /// <param name="thinkness"></param>
        /// <returns></returns>
        protected override void Draw(List <Vector2D> points)
        {
            DrawingContext dc = this.RenderOpen();

            Pen.Freeze();  //冻结画笔,这样能加快绘图速度
            for (int i = 0; i < points.Count - 1; i++)
            {
                dc.DrawLine(Pen, KernelProperty.MMToPix(points[i]), KernelProperty.MMToPix(points[i + 1]));
            }
            var line = Line2D.Create(start, end);

            this.DrawArrow(dc, line);
            SeText(dc, line);
            dc.Close();
        }
コード例 #21
0
ファイル: DrawingControl.cs プロジェクト: AlbertMin/AlbertCAD
        /// <summary>
        /// 鼠标的移动事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void DrawingControl_MouseMove(object sender, System.Windows.Input.MouseEventArgs e)
        {
            Vector2D p = KernelProperty.PixToMM(e.GetPosition(this));

            //清除当前所有的捕捉点
            this.SetIntersectPointCatch(null);

            //按着中间键,说明只是想拖动
            if (IsDraging)
            {
                this.DragMoveView(e.GetPosition(this));
            }
            else
            {
                if (EAction != null)
                {
                    //假如在绘制过程中,则直接捕获兴趣点
                    IntersectPoint catchPoint = GetIntersectPointCatch(p);


                    //假如设置当前橡皮筋效果
                    if (EAction.Geometry != null)
                    {
                        //进行橡皮筋效果
                        if (EAction.Geometry.IsActioning)
                        {
                            if (catchPoint != null)
                            {
                                EAction.Erase(catchPoint.Point);
                            }
                            else
                            {
                                EAction.Erase(p);
                            }
                        }
                    }
                }
                else
                {
                    //判断当前是否是框选状态
                    if (isBoxSelect)
                    {
                        SelectionBoxCatch.Select(p);
                    }
                }
            }
        }
コード例 #22
0
        /// <summary>
        /// 设置当前的样式
        /// </summary>
        /// <param name="text"></param>
        public void SetText(string text, Vector2D p, double angle)
        {
            this.IsOpen = true;
            var textPoint = KernelProperty.MMToPix(p);

            this.HorizontalOffset = textPoint.X;
            this.VerticalOffset   = textPoint.Y;
            RotateTransform rtf = new RotateTransform();

            rtf.CenterX          = textPoint.X;
            rtf.CenterY          = textPoint.Y;
            rtf.Angle            = angle;
            this.RenderTransform = rtf;
            textBox.Text         = text;
            textBox.Focus();
            this.SetDefault();
        }
コード例 #23
0
ファイル: DrawingControl.cs プロジェクト: AlbertMin/AlbertCAD
        /// <summary>
        /// 鼠标的滚动事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void DrawingControl_MouseWheel(object sender, System.Windows.Input.MouseWheelEventArgs e)
        {
            if (!IsDraging)
            {
                if (e.Delta > 0)
                {
                    KernelProperty.ZoomIn(e.GetPosition(this));
                }
                else
                {
                    KernelProperty.ZoomOut(e.GetPosition(this));
                }

                this.Update();

                this.RemoveTemporaryVisualsByType(0);
            }
        }
コード例 #24
0
        /// <summary>
        /// 给当前线段绘制箭头
        /// </summary>
        /// <param name="line"></param>
        protected virtual void DrawArrow(DrawingContext dc, Line2D line)
        {
            this.dashStyle = null;
            var    start  = line.Start;
            Line3D line3d = Line3D.Create(Vector3D.Create(line.Start.X, line.Start.Y, 0), Vector3D.Create(line.End.X, line.End.Y, 0));
            var    dir    = line3d.Direction.Cross(Vector3D.BasisZ);
            var    ndir   = Vector2D.Create(dir.X, dir.Y);
            var    v1     = start.Offset(ndir * KernelProperty.PixToMM(5)).Offset(line.Direction * KernelProperty.PixToMM(5));
            var    v2     = start.Offset(-ndir * KernelProperty.PixToMM(5)).Offset(line.Direction * KernelProperty.PixToMM(5));

            dc.DrawLine(Pen, KernelProperty.MMToPix(start), KernelProperty.MMToPix(v1));
            dc.DrawLine(Pen, KernelProperty.MMToPix(v2), KernelProperty.MMToPix(start));
            var end = line.End;
            var v3  = end.Offset(ndir * KernelProperty.PixToMM(5)).Offset(-line.Direction * KernelProperty.PixToMM(5));
            var v4  = end.Offset(-ndir * KernelProperty.PixToMM(5)).Offset(-line.Direction * KernelProperty.PixToMM(5));

            dc.DrawLine(Pen, KernelProperty.MMToPix(end), KernelProperty.MMToPix(v3));
            dc.DrawLine(Pen, KernelProperty.MMToPix(v4), KernelProperty.MMToPix(end));
        }
コード例 #25
0
        /// <summary>
        /// 绘制当前图形的选择
        /// </summary>
        /// <param name="points"></param>
        protected override void Draw(List <Vector2D> points)
        {
            //冻结画笔,这样能加快绘图速度
            DrawingContext dc = this.RenderOpen();

            Pen.Freeze();
            this.DashStyle = null;
            if (IntersectGeometry.GeometryShape != null)
            {
                //获取当前图形上所有的点
                var npoints = IntersectGeometry.GeometryShape.Points;
                if (npoints != null)
                {
                    //绘制矩形
                    npoints.ForEach(x =>
                    {
                        drawRect(dc, x);
                    });
                }

                if (IntersectGeometry.GeometryShape.Emphasize != null)
                {
                    IntersectGeometry.GeometryShape.Emphasize.ForEach(x => {
                        this.DashStyle      = new System.Windows.Media.DashStyle(new double[] { 5, 5 }, 10);
                        this.PenColor       = Colors.DarkGreen;
                        this.Pen.EndLineCap = PenLineCap.Triangle;
                        dc.DrawLine(Pen, KernelProperty.MMToPix(x.Start), KernelProperty.MMToPix(x.End));
                    });
                }
            }
            //获取兴趣的线
            if (IntersectGeometry.IntersectPoint != null && IntersectGeometry.IntersectPoint.Line != null)
            {
                var l = IntersectGeometry.IntersectPoint.Line;
                this.DashStyle      = new System.Windows.Media.DashStyle(new double[] { 5, 5 }, 10);
                this.PenColor       = Colors.Blue;
                this.Pen.EndLineCap = PenLineCap.Triangle;
                dc.DrawLine(Pen, KernelProperty.MMToPix(l.Start), KernelProperty.MMToPix(l.End));
            }


            dc.Close();
        }
コード例 #26
0
ファイル: PickedGeometry.cs プロジェクト: AlbertMin/AlbertCAD
        /// <summary>
        /// 绘制当前图形的选择
        /// </summary>
        /// <param name="points"></param>
        protected override void Draw(List <Vector2D> points)
        {
            //冻结画笔,这样能加快绘图速度
            DrawingContext dc = this.RenderOpen();

            Pen.Freeze();
            //获取兴趣的线
            if (IntersectGeometry.IntersectPoint != null && IntersectGeometry.IntersectPoint.Line != null)
            {
                var l = IntersectGeometry.IntersectPoint.Line;
                this.DashStyle      = new System.Windows.Media.DashStyle(new double[] { 5, 5 }, 10);
                this.PenColor       = Colors.Red;
                this.Pen.EndLineCap = PenLineCap.Triangle;
                dc.DrawLine(Pen, KernelProperty.MMToPix(l.Start), KernelProperty.MMToPix(l.End));
            }


            dc.Close();
        }
コード例 #27
0
        /// <summary>
        /// 根据所有的点,组成一个封闭区域,且可以填充,并且填充
        /// </summary>
        /// <param name="points"></param>
        /// <param name="brush"></param>
        protected virtual void DrawFill(List <Vector2D> points)
        {
            DrawingContext dc = this.RenderOpen();

            Pen.Freeze();  //冻结画笔,这样能加快绘图速度
            PathGeometry paths = new PathGeometry();

            PathFigureCollection pfc = new PathFigureCollection();
            PathFigure           pf  = new PathFigure();

            pfc.Add(pf);
            pf.StartPoint = KernelProperty.MMToPix(points[0]);
            for (int i = 0; i < points.Count; i++)
            {
                LineSegment ps = new LineSegment();
                ps.Point = KernelProperty.MMToPix(points[i]);
                pf.Segments.Add(ps);
            }
            pf.IsClosed   = true;
            paths.Figures = pfc;
            dc.DrawGeometry(Brush, Pen, paths);
            dc.Close();
        }
コード例 #28
0
        /// <summary>
        /// 刷新当前图形元素
        /// </summary>
        public override void Update()
        {
            DrawingContext dc = this.RenderOpen();

            Pen.Freeze();  //冻结画笔,这样能加快绘图速度
            this.DashStyle      = new System.Windows.Media.DashStyle(new double[] { 5, 5 }, 10);
            this.PenColor       = Colors.DeepSkyBlue;
            this.Pen.EndLineCap = PenLineCap.Triangle;
            ArcSegment arc = new ArcSegment();

            arc.IsLargeArc = true;
            if (start.AngleFrom(end) >= Math.PI)
            {
                arc.IsLargeArc = false;
            }
            else
            {
                arc.IsLargeArc = true;
            }
            arc.RotationAngle = 0;
            arc.Size          = new System.Windows.Size(100, 100);
            arc.Point         = KernelProperty.MMToPix(this.end);
            PathGeometry paths = new PathGeometry();

            paths.FillRule = FillRule.EvenOdd;
            PathFigureCollection pfc = new PathFigureCollection();
            PathFigure           pf  = new PathFigure();

            pfc.Add(pf);
            pf.StartPoint = KernelProperty.MMToPix(this.start);
            pf.Segments.Add(arc);
            paths.Figures = pfc;
            dc.DrawGeometry(Brush, Pen, paths);
            SeText(dc, Line2D.Create(start, end));
            dc.Close();
        }
コード例 #29
0
ファイル: DrawingControl.cs プロジェクト: AlbertMin/AlbertCAD
        /// <summary>
        /// 鼠标的按下事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void DrawingControl_MouseLeftButtonDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
        {
            //进行坐标转化
            Vector2D p = KernelProperty.PixToMM(e.GetPosition(this));

            if (EAction != null)
            {
                if (EAction is DrawingKernel.Commands.ICommand && (EAction as DrawingKernel.Commands.ICommand).GetTarget() == null)
                {
                    //没有绘制动作,则是物品选择
                    isBoxSelect = true;
                    //开始进行选择操作
                    SelectionBoxCatch.SelectStart(p);
                }
                else
                {
                    IntersectPoint catchPoint = GetIntersectPointCatch(p);

                    //设置捕获点
                    if (catchPoint != null)
                    {
                        EAction.SetPoint(catchPoint.Point);
                    }
                    else
                    {
                        EAction.SetPoint(p);
                    }
                }
            }
            else
            {
                //没有绘制动作,则是物品选择
                isBoxSelect = true;
                SelectionBoxCatch.SelectStart(p);
            }
        }
コード例 #30
0
 /// <summary>
 /// 绘制当前直线
 /// </summary>
 public override void Update()
 {
     if (Start != null && end != null)
     {
         //对直线矩形偏移
         Line3D subline3d       = Line3D.Create(Vector3D.Create(Start.X, Start.Y, 0), Vector3D.Create(end.X, end.Y, 0));
         var    offsetDirection = subline3d.Direction.Cross(Vector3D.BasisZ);
         //获取偏移量
         var offsetdir = Vector2D.Create(offsetDirection.X, offsetDirection.Y) * KernelProperty.PixToMM(SublineOffset);
         //添加偏移
         var             offline = Line2D.Create(Start, end).Offset(offsetdir);
         List <Vector2D> points  = new List <Vector2D>();
         this.DashStyle      = new System.Windows.Media.DashStyle(new double[] { 5, 5 }, 10);
         this.PenColor       = Colors.DeepSkyBlue;
         this.Pen.EndLineCap = PenLineCap.Triangle;
         points.Add(Start);
         points.Add(offline.Start);
         points.Add(offline.End);
         points.Add(end);
         this.Draw(points);
     }
 }