Esempio n. 1
0
        public eDrawObjectMouseDown OnMouseDown(ICanvas canvas, UnitPoint point, ISnapPoint snappoint)
        {
            if (snappoint is SnapPointBase && snappoint.Owner is RectBase)
            {
                NodePointMultiConnectionLine.ePoint pointType = HitUtil.Distance(point, m_p1) < HitUtil.Distance(point, m_p2) ?
                                                                NodePointMultiConnectionLine.ePoint.P1 : NodePointMultiConnectionLine.ePoint.P2;
                RectBase rect = snappoint.Owner as RectBase;
                rect.AttachConnectionCrvNode(new NodePointMultiConnectionLine(this, pointType));
                if (pointType == NodePointMultiConnectionLine.ePoint.P1)
                {
                    m_p1 = point;
                }
                else
                {
                    m_p2 = point;
                }
                return(eDrawObjectMouseDown.Done);
            }

            OnMouseMove(canvas, point);
            Selected = false;
            if (m_allPts == null || m_allPts.Count < 2)
            {
                return(eDrawObjectMouseDown.Cancel);
            }
            return(eDrawObjectMouseDown.Done);
        }
Esempio n. 2
0
 public override void OnMouseMove(ICanvas canvas, UnitPoint unitPoint)
 {
     base.OnMouseMove(canvas, unitPoint);
     if (this.CurrentPoint == MultiSegementLineCurrentPoint.StartPoint)
     {
         this.p1     = unitPoint;
         this.Points = new List <UnitPointBulge>();
         Points.Add(new UnitPointBulge(this.p1));
     }
     else if (this.CurrentPoint == MultiSegementLineCurrentPoint.MidPoint)
     {
         this.p2 = unitPoint;
         this.Points.Clear();
         this.rectPoint.Clear();
         this.Points.Add(new UnitPointBulge(this.p1));
         this.Points.Add(new UnitPointBulge(new UnitPoint(this.p2.X, this.p1.Y)));
         this.Points.Add(new UnitPointBulge(this.p2));
         this.Points.Add(new UnitPointBulge(new UnitPoint(this.p1.X, this.p2.Y)));
         this.maxRadius = this.GetMinSideLen() / 2;
         for (int i = 0; i < this.PointCount; i++)
         {
             this.rectPoint.Add(this.Points[i].Point);
         }
         return;
     }
     else if (this.CurrentPoint == MultiSegementLineCurrentPoint.EndPoint)
     {
         this.p3 = unitPoint;
         double radius = HitUtil.Distance(unitPoint, this.p2);
         this.CalculateRoundParams(radius);
     }
 }
Esempio n. 3
0
 public ISnapPoint SnapPoint(ICanvas canvas, UnitPoint point, List <IDrawObject> otherobj, Type[] runningsnaptypes, Type usersnaptype)
 {
     try
     {
         if (Type == BezierType.Bezier)
         {
             if (HitUtil.Distance(point, m_p1, true) <= 0.2)
             {
                 return(new VertextSnapPoint(canvas, this, m_p1));
             }
             if (HitUtil.Distance(point, m_p2, true) <= 0.2)
             {
                 return(new VertextSnapPoint(canvas, this, m_p2));
             }
             if (HitUtil.Distance(point, m_p3, true) <= 0.2)
             {
                 return(new VertextSnapPoint(canvas, this, m_p3));
             }
             if (HitUtil.Distance(point, m_p4, true) <= 0.2)
             {
                 return(new VertextSnapPoint(canvas, this, m_p4));
             }
         }
         return(null);
     }
     catch (Exception ex)
     { throw ex; }
 }
Esempio n. 4
0
 public virtual void OnMouseMove(ICanvas canvas, UnitPoint point)
 {
     m_lastPoint = point;
     if (m_curPoint == eCurrentPoint.p1)
     {
         m_p1 = point;
         return;
     }
     if (m_curPoint == eCurrentPoint.p2)
     {
         m_p2 = point;
         return;
     }
     if (m_curPoint == eCurrentPoint.p3)
     {
         m_p3 = point;
         UpdateCircleFrom3Points();
         return;
     }
     if (m_curPoint == eCurrentPoint.center)
     {
         m_center = point;
     }
     if (m_curPoint == eCurrentPoint.radius)
     {
         //StartAngle = 0;
         //EndAngle = 360;
         m_radius = (float)HitUtil.Distance(m_center, point);
     }
 }
Esempio n. 5
0
 public override void OnMouseMove(ICanvas canvas, UnitPoint unitPoint)
 {
     if (this.arcCurrentPointType == ArcCurrentPointType.Center)
     {
         this.Center = unitPoint;
         return;
     }
     if (this.arcCurrentPointType == ArcCurrentPointType.StartPoint)
     {
         this.StartAngle = (float)HitUtil.RadiansToDegrees(HitUtil.LineAngleR(this.Center, unitPoint, 0));
         this.AngleSweep = 360;
         if (float.IsNaN(this.InRadiusValue))
         {
             this.Radius     = (float)HitUtil.Distance(this.Center, unitPoint);
             this.startPoint = unitPoint;
         }
         else
         {
             this.Radius     = InRadiusValue;
             this.startPoint = new UnitPoint(this.Radius * Math.Cos(HitUtil.DegreesToRadians(StartAngle)) + this.Center.X, this.Radius * Math.Sin(HitUtil.DegreesToRadians(StartAngle)) + this.Center.Y);
         }
         return;
     }
     if (this.arcCurrentPointType == ArcCurrentPointType.EndPoint)
     {
         float endAngle = (float)HitUtil.RadiansToDegrees(HitUtil.LineAngleR(this.Center, unitPoint, 0));
         this.AngleSweep = endAngle - this.StartAngle;
         this.AngleSweep = this.AngleSweep > 0 ? this.AngleSweep : this.AngleSweep + 360;
         this.endPoint   = new UnitPoint(this.Radius * Math.Cos(HitUtil.DegreesToRadians(endAngle)) + this.Center.X, this.Radius * Math.Sin(HitUtil.DegreesToRadians(endAngle)) + this.Center.Y);
         return;
     }
 }
Esempio n. 6
0
 /// <summary>
 /// 获取图形信息用于显示在面板下方
 /// </summary>
 /// <returns></returns>
 string IDrawObject.GetInfoAsString()
 {
     return(string.Format("bezierCurve@{0},{1} - L={2:f4}<{3:f4}",
                          P1.PosAsString(),
                          P4.PosAsString(),
                          HitUtil.Distance(P1, P4),
                          HitUtil.RadiansToDegrees(HitUtil.LineAngleR(P1, P4, 0))));
 }
Esempio n. 7
0
        private double GetMinSideLen()
        {
            double sideLen  = HitUtil.Distance(this.Points[0].Point, this.Points[1].Point);
            double sideLen2 = HitUtil.Distance(this.Points[1].Point, this.Points[2].Point);
            double minSide  = sideLen > sideLen2 ? sideLen2 : sideLen;

            return(minSide);
        }
Esempio n. 8
0
 public string GetInfoAsString()
 {
     return(string.Format("Line@{0},{1} - L={2:f4}<{3:f4}",
                          P1.PosAsString(),
                          P2.PosAsString(),
                          HitUtil.Distance(P1, P2),
                          HitUtil.RadiansToDegrees(HitUtil.LineAngleR(P1, P2, 0))));
 }
Esempio n. 9
0
        public static double CalTwoLinesAngleFromThreePoints(UnitPoint p1, UnitPoint p2, UnitPoint p3)
        {
            double p12   = HitUtil.Distance(p1, p2);
            double p23   = HitUtil.Distance(p2, p3);
            double p13   = HitUtil.Distance(p1, p3);
            double cosA  = (p12 * p12 + p23 * p23 - p13 * p13) / (2 * p12 * p23);
            double angle = Math.Acos(cosA);

            return(angle);
        }
Esempio n. 10
0
 public void SetPosition(UnitPoint unitPoint)
 {
     if (this.circleNodeType != CircleNodeType.Center)
     {
         this.clone.Radius = (float)HitUtil.Distance(this.clone.Center, unitPoint);
     }
     else
     {
         UnitPoint offset = new UnitPoint(unitPoint.X - this.clone.Center.X, unitPoint.Y - this.clone.Center.Y);
         this.clone.Move(offset);
     }
 }
Esempio n. 11
0
        private void CalculateVertexPoints(UnitPoint centerPoint, UnitPoint vertexPoint)
        {
            double startAngle = HitUtil.LineAngleR(centerPoint, vertexPoint, 0);
            double radius     = HitUtil.Distance(centerPoint, vertexPoint, true);
            double stepAngle  = 360 / this.SideCount;

            for (int i = 0; i < this.SideCount; i++)
            {
                UnitPoint point = HitUtil.PointOnCircle(centerPoint, radius, startAngle + stepAngle * Math.PI / 180 * i);
                this.Points.Add(new UnitPointBulge(point));
            }
        }
Esempio n. 12
0
 private UnitPoint HandleSideBoundError(UnitPoint mousePoint, UnitPoint unitPoint1, UnitPoint unitPoint2, float threshWidth)
 {
     if (HitUtil.Distance(mousePoint, unitPoint1) <= threshWidth)
     {
         return(unitPoint1);
     }
     if (HitUtil.Distance(mousePoint, unitPoint2) <= threshWidth)
     {
         return(unitPoint2);
     }
     return(mousePoint);
 }
Esempio n. 13
0
        private void GetCircleLeadLineParams(IDrawObject drawObject, LineInOutParamsModel leadInOutParamsModel)
        {
            Circle circle = (Circle)drawObject;
            double angle  = HitUtil.LineAngleR(circle.Center, this.p2, 0);

            leadInOutParamsModel.FigureTotalLength = (float)(angle / (Math.PI * 2));
            this.p2 = HitUtil.PointOnCircle(circle.Center, circle.Radius, angle);
            bool isInner;

            leadInOutParamsModel.LineInAngle  = DrawingOperationHelper.GetLeadLineAngleArc(this.p1, this.p2, circle.Center, circle.IsClockwise, out isInner);
            leadInOutParamsModel.LineInLength = (float)HitUtil.Distance(this.p1, this.p2);
            circle.IsInnerCut = isInner;
        }
Esempio n. 14
0
        /*
         * public void GetObjectData(XmlWriter wr)
         * {
         *  wr.WriteStartElement("line");
         *  XmlUtil.WriteProperties(this, wr);
         *  wr.WriteEndElement();
         * }
         * public void AfterSerializedIn()
         * {
         * }
         * */
        #endregion

        public void ExtendLineToPoint(UnitPoint newpoint)
        {
            UnitPoint newlinepoint = HitUtil.NearestPointOnLine(P1, P2, newpoint, true);

            if (HitUtil.Distance(newlinepoint, P1) < HitUtil.Distance(newlinepoint, P2))
            {
                P1 = newlinepoint;
            }
            else
            {
                P2 = newlinepoint;
            }
        }
Esempio n. 15
0
        public void ExtendLineToPoint(UnitPoint unitPoint)
        {
            UnitPoint newLinePoint = HitUtil.NearestPointOnLine(this.P1, this.P2, unitPoint, true);

            if (HitUtil.Distance(newLinePoint, this.P1) < HitUtil.Distance(newLinePoint, this.P2))
            {
                this.P1 = newLinePoint;
            }
            else
            {
                this.P2 = newLinePoint;
            }
        }
Esempio n. 16
0
        public static UnitPoint GetBulgeMidPoint(UnitPoint p1, UnitPoint p2, double bulge)
        {
            bool      clockwise  = bulge >= 0 ? false : true;
            UnitPoint center     = GetCenterByBulgeAndTwoPoints(p1, p2, bulge);
            float     radius     = (float)HitUtil.Distance(center, p1);
            float     startAngle = (float)HitUtil.RadiansToDegrees(HitUtil.LineAngleR(center, p1, 0));
            float     EndAngle   = (float)HitUtil.RadiansToDegrees(HitUtil.LineAngleR(center, p2, 0));
            float     sweepAngle = (float)HitUtil.CalAngleSweep(startAngle, EndAngle, clockwise);
            float     midAngle   = startAngle + sweepAngle / 2;
            UnitPoint midPoint   = new UnitPoint(radius * Math.Cos(HitUtil.DegreesToRadians(midAngle)) + center.X, radius * Math.Sin(HitUtil.DegreesToRadians(midAngle)) + center.Y);

            return(midPoint);
        }
Esempio n. 17
0
        public ISnapPoint SnapPoint(ICanvas canvas, UnitPoint testPt, List <IDrawObject> otherobj, Type[] runningsnaptypes, Type usersnaptype)
        {
            float thWidth = Line.ThresholdWidth(canvas, Width, ThresholdPixel);

            if (runningsnaptypes != null)
            {
                foreach (Type snaptype in runningsnaptypes)
                {
                    if (snaptype == typeof(VertextSnapPoint))
                    {
                        if (HitUtil.CircleHitPoint(m_p1, thWidth, testPt))
                        {
                            return(new VertextSnapPoint(canvas, this, m_p1));
                        }
                        if (HitUtil.CircleHitPoint(m_p2, thWidth, testPt))
                        {
                            return(new VertextSnapPoint(canvas, this, m_p2));
                        }
                    }
                    if (snaptype == typeof(MidpointSnapPoint))
                    {
                        if (HitUtil.CircleHitPoint(m_center, thWidth, testPt))
                        {
                            return(new MidpointSnapPoint(canvas, this, m_center));
                        }
                    }
                }
                return(null);
            }
            if (usersnaptype == typeof(MidpointSnapPoint))
            {
                float[] midPt = { 0.0f, 0.0f };
                m_crv.Eval(0.5f, ref midPt[0], ref midPt[1]);
                return(new MidpointSnapPoint(canvas, this, new UnitPoint(midPt[0], midPt[1])));
            }
            if (usersnaptype == typeof(VertextSnapPoint))
            {
                double d1 = HitUtil.Distance(testPt, m_p1);
                double d2 = HitUtil.Distance(testPt, m_p2);
                if (d1 <= d2)
                {
                    return(new VertextSnapPoint(canvas, this, m_p1));
                }
                return(new VertextSnapPoint(canvas, this, m_p2));
            }
            if (usersnaptype == typeof(CenterSnapPoint))
            {
                return(new CenterSnapPoint(canvas, this, m_center));
            }
            return(null);
        }
Esempio n. 18
0
        private void CalculateVertexPoints2(UnitPoint centerPoint, UnitPoint vertexPoint)
        {
            double startAngle = HitUtil.LineAngleR(centerPoint, this.Points[1].Point, 0);
            double r          = HitUtil.Distance(centerPoint, vertexPoint, true);
            double stepAngle  = 360 / this.SideCount;

            for (int i = 0; i < this.Points.Count; i++)
            {
                if (i % 2 != 0)
                {
                    UnitPoint point = HitUtil.PointOnCircle(centerPoint, r, startAngle + stepAngle * Math.PI / 180 * (i / 2));
                    this.Points[i] = new UnitPointBulge(point);
                }
            }
        }
Esempio n. 19
0
        public void SetNewPoints(DrawTools.Line l, UnitPoint hitpoint, UnitPoint intersectpoint)
        {
            SetLine(l);
            double hitToVp1 = HitUtil.Distance(hitpoint, l.P1);             // hit point to vertex point
            double ispToVp1 = HitUtil.Distance(intersectpoint, l.P1);       // intersect point to vertex point

            // if hit is closer than intersect point, then keep this point and adjust the other
            if (hitToVp1 <= ispToVp1)
            {
                m_p2 = intersectpoint;
            }
            else
            {
                m_p1 = intersectpoint;
            }
            ResetLine();
        }
Esempio n. 20
0
 /// <summary>
 /// 延长直线
 /// </summary>
 public void ExtendLineToPoint(UnitPoint newpoint)
 {
     try
     {
         UnitPoint newlinepoint = HitUtil.NearestPointOnLine(P1, P2, newpoint, true);
         if (HitUtil.Distance(newlinepoint, P1) < HitUtil.Distance(newlinepoint, P2))
         {
             P1 = newlinepoint;
         }
         else
         {
             P2 = newlinepoint;
         }
     }
     catch (Exception ex)
     { throw ex; }
 }
Esempio n. 21
0
        /*
         * UnitPoint GetPoint()
         * {
         *      if (m_curPoint == Arc3Point.eCurrentPoint.p1)
         *              return m_clone.P1;
         *      if (m_curPoint == Arc3Point.eCurrentPoint.p2)
         *              return m_clone.P2;
         *      if (m_curPoint == Arc3Point.eCurrentPoint.p3)
         *              return m_clone.P3;
         *      if (m_curPoint == Arc3Point.eCurrentPoint.startangle)
         *              return m_clone.P1;
         *      if (m_curPoint == Arc3Point.eCurrentPoint.endangle)
         *              return m_clone.P3;
         *      if (m_curPoint == Arc3Point.eCurrentPoint.radius)
         *              return m_clone.P2;
         *      return UnitPoint.Empty;
         * }
         * */
        void SetPoint(Arc3Point arc, UnitPoint pos)
        {
            if (m_curPoint == Arc3Point.eCurrentPoint.p1)
            {
                arc.P1 = pos;
            }
            if (m_curPoint == Arc3Point.eCurrentPoint.p2)
            {
                arc.P2 = pos;
            }
            if (m_curPoint == Arc3Point.eCurrentPoint.p3)
            {
                arc.P3 = pos;
            }

            double angleToRound = 0;

            if (Control.ModifierKeys == Keys.Control)
            {
                angleToRound = HitUtil.DegressToRadians(45);
            }
            double angleR = HitUtil.LineAngleR(arc.Center, pos, angleToRound);

            if (m_curPoint == Arc3Point.eCurrentPoint.startangle)
            {
                arc.P1 = HitUtil.PointOncircle(arc.Center, arc.Radius, angleR);
            }
            if (m_curPoint == Arc3Point.eCurrentPoint.endangle)
            {
                arc.P3 = HitUtil.PointOncircle(arc.Center, arc.Radius, angleR);
            }
            if (m_curPoint == Arc3Point.eCurrentPoint.radius)
            {
                double radius = HitUtil.Distance(arc.Center, pos);
                arc.P1 = HitUtil.PointOncircle(arc.Center, radius, HitUtil.DegressToRadians(arc.StartAngle));
                arc.P2 = pos;
                arc.P3 = HitUtil.PointOncircle(arc.Center, radius, HitUtil.DegressToRadians(arc.EndAngle));
            }

            arc.UpdateArcFrom3Points();

            if ((m_curPoint == Arc3Point.eCurrentPoint.startangle) || (m_curPoint == Arc3Point.eCurrentPoint.endangle))
            {
                arc.UpdateCenterNodeFromAngles();
            }
        }
Esempio n. 22
0
        public void CalOverCuttingPoints(UnitPoint startPoint, UnitPoint p2, double length, int index)
        {
            double distance = HitUtil.Distance(startPoint, p2);

            if (length > distance)
            {
                this.OverCuttingPoints.Add(p2);
                length -= distance;
                index  += 1;
                this.CalOverCuttingPoints(p2, this.MachinePoints[index], length, index);
            }
            else
            {
                double    angle     = HitUtil.LineAngleR(startPoint, p2, 0);
                UnitPoint unitPoint = HitUtil.PointOnCircle(startPoint, length, angle);
                this.OverCuttingPoints.Add(unitPoint);
            }
        }
Esempio n. 23
0
        /// <summary>
        /// 设置新的点
        /// </summary>
        /// <param name="l"></param>
        /// <param name="hitpoint"></param>
        /// <param name="intersectpoint"></param>
        public void SetNewPoints(DrawTools.Line l, UnitPoint hitpoint, UnitPoint intersectpoint)
        {
            SetLine(l);
            double hitToVp1 = HitUtil.Distance(hitpoint, l.P1);             //点击点到顶点的距离
            double ispToVp1 = HitUtil.Distance(intersectpoint, l.P1);       //交点到顶点的距离

            // if hit is closer than intersect point, then keep this point and adjust the other
            //如果点击点很靠近交点,就保持这个点然后调整其他的点
            if (hitToVp1 <= ispToVp1)
            {
                m_p2 = intersectpoint;
            }
            else
            {
                m_p1 = intersectpoint;
            }
            ResetLine();
        }
Esempio n. 24
0
        public virtual void OnMouseMove(ICanvas canvas, UnitPoint point)
        {
            m_lastPoint = point;
            if (m_curPoint == eCurrentPoint.p1)
            {
                m_p1   = point;
                Center = point;
                return;
            }
            if (m_curPoint == eCurrentPoint.p2)
            {
                StartAngle = 0;
                EndAngle   = 360;
                Center     = HitUtil.LineMidpoint(m_p1, point);
                m_radius   = (float)HitUtil.Distance(m_center, point);
                return;
            }
            if (m_curPoint == eCurrentPoint.center)
            {
                Center = point;
            }
            if (m_curPoint == eCurrentPoint.radius)
            {
                //StartAngle = 0;
                //EndAngle = 360;
                m_radius = (float)HitUtil.Distance(m_center, point);
            }

            double angleToRound = 0;

            if (Control.ModifierKeys == Keys.Control)
            {
                angleToRound = HitUtil.DegressToRadians(45);
            }

            if (m_curPoint == eCurrentPoint.startAngle)
            {
                StartAngle = (float)HitUtil.RadiansToDegrees(HitUtil.LineAngleR(m_center, point, angleToRound));
            }
            if (m_curPoint == eCurrentPoint.endAngle)
            {
                EndAngle = (float)HitUtil.RadiansToDegrees(HitUtil.LineAngleR(m_center, point, angleToRound));
            }
        }
Esempio n. 25
0
 /// <summary>
 /// 处理鼠标的点击的坐标是否靠近吸附点上
 /// </summary>
 public void SetNewPoints(LineTool l, UnitPoint hitpoint, UnitPoint intersectpoint)
 {
     try
     {
         SetLine(l);
         double hitToVp1 = HitUtil.Distance(hitpoint, l.P1);
         double ispToVp1 = HitUtil.Distance(intersectpoint, l.P1);
         if (hitToVp1 <= ispToVp1)
         {
             m_p2 = intersectpoint;
         }
         else
         {
             m_p1 = intersectpoint;
         }
         ResetLine();
     }
     catch (Exception ex)
     { throw ex; }
 }
        private float GetPercentInPolylineByPoint(IDrawObject drawObject, UnitPoint unitPoint)
        {
            MultiSegmentLineBase item = (MultiSegmentLineBase)drawObject;
            int   segment             = DrawingOperationHelper.GetPointInLineIndex(item, unitPoint);
            int   nextIndex           = (segment + 1 >= item.PointCount) ? 0 : segment + 1;
            float percent;

            if (double.IsNaN(item.Points[segment].Bulge))
            {
                double partLen = HitUtil.Distance(item.Points[segment].Point, unitPoint);
                double allLen  = HitUtil.Distance(item.Points[segment].Point, item.Points[nextIndex].Point);
                percent = (float)(segment + partLen / allLen);
            }
            else
            {
                DrawModel.ArcModelMini arcModelMini = DrawingOperationHelper.GetArcParametersFromBulge(item.Points[segment].Point, item.Points[nextIndex].Point, (float)item.Points[segment].Bulge);
                percent = segment + DrawingOperationHelper.GetPercentInArcByPoint(arcModelMini, unitPoint);
            }
            return((float)(DrawingOperationHelper.GetLengthByPositionInPolyLine(item.Points, item.IsCloseFigure, percent) / item.SizeLength));
        }
Esempio n. 27
0
 public eDrawObjectMouseDown OnMouseDown(ICanvas canvas, UnitPoint point, ISnapPoint snappoint)
 {
     Selected = false;
     OnMouseMove(canvas, point);
     if (snappoint is PerpendicularSnapPoint && snappoint.Owner is Line)
     {
         Line src = snappoint.Owner as Line;
         m_p2 = HitUtil.NearestPointOnLine(src.P1, src.P2, m_p1, true);
         return(eDrawObjectMouseDown.DoneRepeat);
     }
     if (snappoint is PerpendicularSnapPoint && snappoint.Owner is Arc)
     {
         Arc src = snappoint.Owner as Arc;
         m_p2 = HitUtil.NearestPointOnCircle(src.Center, src.Radius, m_p1, 0);
         return(eDrawObjectMouseDown.DoneRepeat);
     }
     if (snappoint is SnapPointBase && snappoint.Owner is RectBase)
     {
         NodePointCubicBezier.ePoint pointType = HitUtil.Distance(point, m_p1) < HitUtil.Distance(point, m_p2) ?
                                                 NodePointCubicBezier.ePoint.P1 : NodePointCubicBezier.ePoint.P2;
         RectBase rect = snappoint.Owner as RectBase;
         rect.AttachConnectionCrvNode(new NodePointCubicBezier(this, pointType));
         if (pointType == NodePointCubicBezier.ePoint.P1)
         {
             m_p1 = point;
         }
         else
         {
             m_p2 = point;
         }
         UpdateCtrlPts();
         return(eDrawObjectMouseDown.Done);
     }
     if (Control.ModifierKeys == Keys.Control)
     {
         point = HitUtil.OrthoPointD(m_p1, point, 45);
     }
     m_p2 = point;
     UpdateCtrlPts();
     return(eDrawObjectMouseDown.Done);
 }
Esempio n. 28
0
        /// <summary>
        /// 根据三个点来更新圆弧
        /// </summary>
        public void UpdateArcFrom3Points()
        {
            //Console.WriteLine("UpdateArcFrom3Points()");
            m_center   = HitUtil.CenterPointFrom3Points(m_p1, m_p2, m_p3);
            m_radius   = (float)HitUtil.Distance(m_center, m_p1);
            StartAngle = (float)HitUtil.RadiansToDegrees(HitUtil.LineAngleR(m_center, m_p1, 0));
            EndAngle   = (float)HitUtil.RadiansToDegrees(HitUtil.LineAngleR(m_center, m_p3, 0));
            // find angle from P1 on line P1|P3 to P2. If this angle is 0-180 the direction is CCW else it is CW

            double p1p3angle = HitUtil.RadiansToDegrees(HitUtil.LineAngleR(m_p1, m_p3, 0));
            double p1p2angle = HitUtil.RadiansToDegrees(HitUtil.LineAngleR(m_p1, m_p2, 0));
            double diff      = p1p3angle - p1p2angle;

            //我知道这个逻辑存在问题,在某些情况下,圆弧的绘制不跟随鼠标,
            //但是现在也会奏效。
            Direction = eDirection.kCCW;
            if (diff < 0 || diff > 180)
            {
                Direction = eDirection.kCW;
            }

            if (p1p3angle == 0)
            {
                if (diff < -180)
                {
                    Direction = eDirection.kCCW;
                }
                else
                {
                    Direction = eDirection.kCW;
                }
            }
            if (p1p3angle == 90)
            {
                if (diff < -180)
                {
                    Direction = eDirection.kCCW;
                }
            }
        }
Esempio n. 29
0
        public void UpdateArcFrom3Points()
        {
            m_center   = HitUtil.CenterPointFrom3Points(m_p1, m_p2, m_p3);
            m_radius   = (float)HitUtil.Distance(m_center, m_p1);
            StartAngle = (float)HitUtil.RadiansToDegrees(HitUtil.LineAngleR(m_center, m_p1, 0));
            EndAngle   = (float)HitUtil.RadiansToDegrees(HitUtil.LineAngleR(m_center, m_p3, 0));
            // find angle from P1 on line P1|P3 to P2. If this angle is 0-180 the direction is CCW else it is CW

            double p1p3angle = HitUtil.RadiansToDegrees(HitUtil.LineAngleR(m_p1, m_p3, 0));
            double p1p2angle = HitUtil.RadiansToDegrees(HitUtil.LineAngleR(m_p1, m_p2, 0));
            double diff      = p1p3angle - p1p2angle;

            // I know there is a problem with this logic, in some cases the arc does not follow the mouse,
            // but it will work for now.
            Direction = eDirection.kCCW;
            if (diff < 0 || diff > 180)
            {
                Direction = eDirection.kCW;
            }

            if (p1p3angle == 0)
            {
                if (diff < -180)
                {
                    Direction = eDirection.kCCW;
                }
                else
                {
                    Direction = eDirection.kCW;
                }
            }
            if (p1p3angle == 90)
            {
                if (diff < -180)
                {
                    Direction = eDirection.kCCW;
                }
            }
        }
Esempio n. 30
0
        public void UpdateArcFrom3Points()
        {
            try
            {
                m_center   = HitUtil.CenterPointFrom3Points(m_p1, m_p2, m_p3);
                m_radius   = (float)HitUtil.Distance(m_center, m_p1);
                StartAngle = (float)HitUtil.RadiansToDegrees(HitUtil.LineAngleR(m_center, m_p1, 0));
                EndAngle   = (float)HitUtil.RadiansToDegrees(HitUtil.LineAngleR(m_center, m_p3, 0));
                double p1p3angle = HitUtil.RadiansToDegrees(HitUtil.LineAngleR(m_p1, m_p3, 0));
                double p1p2angle = HitUtil.RadiansToDegrees(HitUtil.LineAngleR(m_p1, m_p2, 0));
                double diff      = p1p3angle - p1p2angle;
                Direction = eDirection.kCCW;
                if (diff < 0 || diff > 180)
                {
                    Direction = eDirection.kCW;
                }

                if (p1p3angle == 0)
                {
                    if (diff < -180)
                    {
                        Direction = eDirection.kCCW;
                    }
                    else
                    {
                        Direction = eDirection.kCW;
                    }
                }
                if (p1p3angle == 90)
                {
                    if (diff < -180)
                    {
                        Direction = eDirection.kCCW;
                    }
                }
            }
            catch (Exception ex)
            { throw ex; }
        }