コード例 #1
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;
     }
 }
コード例 #2
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))));
 }
コード例 #3
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))));
 }
コード例 #4
0
 public NodePointCircleRadius(Circle3Point owner)
 {
     m_owner = owner;
     m_clone = m_owner.Clone() as Circle3Point;
     m_clone.CurrentPoint = m_owner.CurrentPoint;
     m_originalValue      = m_owner.Radius;
     Angle1 = (float)HitUtil.RadiansToDegrees(HitUtil.LineAngleR(m_owner.Center, m_owner.P1, 0));
     Angle2 = (float)HitUtil.RadiansToDegrees(HitUtil.LineAngleR(m_owner.Center, m_owner.P2, 0));
     Angle3 = (float)HitUtil.RadiansToDegrees(HitUtil.LineAngleR(m_owner.Center, m_owner.P3, 0));
 }
コード例 #5
0
ファイル: BulgeHelper.cs プロジェクト: liyangTeam/WSXCut
        /// <summary>
        /// 根据圆心,圆上起始点,结束点及圆的时针方向计算圆弧凸度
        /// </summary>
        /// <param name="center">圆心</param>
        /// <param name="startPoint">起始点</param>
        /// <param name="endPoint">结束点</param>
        /// <param name="clockwise">时针方向</param>
        /// <returns></returns>
        public static double GetBulgeFromTwoPointsAndCenter(UnitPoint center, UnitPoint startPoint, UnitPoint endPoint, bool clockwise)
        {
            double startAngle = HitUtil.LineAngleR(center, startPoint, 0);
            double endAngle   = HitUtil.LineAngleR(center, endPoint, 0);
            double sweepAngle = HitUtil.CalAngleSweep(HitUtil.RadiansToDegrees(startAngle), HitUtil.RadiansToDegrees(endAngle), clockwise);

            sweepAngle = Math.Abs(HitUtil.DegreesToRadians(sweepAngle) / 4);
            double bulge = Math.Tan(sweepAngle);

            bulge = clockwise ? -bulge : bulge;
            return(bulge);
        }
コード例 #6
0
ファイル: BulgeHelper.cs プロジェクト: liyangTeam/WSXCut
        private static double IsCorrectCenter(UnitPoint center, double radius, double bulge, UnitPoint p1, UnitPoint p2)
        {
            double    startAngle = HitUtil.RadiansToDegrees(HitUtil.LineAngleR(center, p1, 0));
            double    endAngle   = HitUtil.RadiansToDegrees(HitUtil.LineAngleR(center, p2, 0));
            bool      clockwise  = bulge >= 0 ? false : true;
            double    sweepAngle = HitUtil.CalAngleSweep(startAngle, endAngle, clockwise);
            double    midAngle   = startAngle + sweepAngle / 2;
            UnitPoint midPoint   = new UnitPoint(radius * Math.Cos(HitUtil.DegreesToRadians(midAngle)) + center.X, radius * Math.Sin(HitUtil.DegreesToRadians(midAngle)) + center.Y);
            double    temp       = BulgeToDegree(bulge);

            return(Math.Abs(temp - Math.Abs(sweepAngle)));
        }
コード例 #7
0
ファイル: BulgeHelper.cs プロジェクト: liyangTeam/WSXCut
        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);
        }
コード例 #8
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));
            }
        }
コード例 #9
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;
                }
            }
        }
コード例 #10
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;
                }
            }
        }
コード例 #11
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; }
        }
コード例 #12
0
ファイル: DataModel.cs プロジェクト: liyangTeam/WSXCut
        public void DoArcFlyingCut(List <IDrawObject> drawObjects, List <IDrawObject> flyArcGroups = null, List <IDrawObject> drawObjectsnew = null, List <IDrawObject> drawObjectsold = null)
        {
            List <IDrawObject> NewDrawobjects = new List <IDrawObject>();

            if (flyArcGroups != null)
            {
                Circle circle    = null;
                Circle newCircle = null;

                foreach (var idraw in flyArcGroups)
                {
                    //按零件飞起,可能有图形不是圆
                    if (!(idraw is Circle))
                    {
                        NewDrawobjects.Add(idraw.Clone());
                        continue;
                    }

                    circle = idraw as Circle;
                    //因超过设定距离,该group只有一个圆
                    if (circle.GroupParam.GroupSN[1] == 0)
                    {
                        NewDrawobjects.Add(circle.Clone());
                        ((Circle)NewDrawobjects[NewDrawobjects.Count - 1]).IsFlyingCut = false;
                        continue;
                    }
                    // 起点修改 StartAngle
                    float StartAngle = (float)HitUtil.RadiansToDegrees(
                        HitUtil.LineAngleR(circle.Center, circle.StartMovePoint, 0));

                    newCircle = new Circle()
                    {
                        Center           = circle.Center,
                        Radius           = circle.Radius,
                        StartAngle       = StartAngle,
                        StartMovePoint   = circle.StartMovePoint,
                        EndMovePoint     = circle.StartMovePoint,
                        IsFlyingCut      = true,
                        FlyingCutLeadOut = circle.FlyingCutLeadOut,
                        GroupParam       = circle.GroupParam
                    };
                    newCircle.LeadIn.Position  = StartAngle / 360.0f;
                    newCircle.LeadOut.Position = StartAngle / 360.0f;
                    NewDrawobjects.Add(newCircle);
                }

                if (NewDrawobjects.Count == 0)
                {
                    return;
                }
            }

            if (drawObjectsnew == null)
            {
                if (NewDrawobjects == null || NewDrawobjects.Count <= 0)//重做
                {
                    NewDrawobjects = drawObjects.ToList();
                    this.DrawingLayer.DeleteObjects(drawObjectsold);
                }
                else
                {
                    int newCount      = NewDrawobjects.Count;
                    int groupCount    = NewDrawobjects.Max(o => o.GroupParam.GroupSN.Count > 1 ? o.GroupParam.GroupSN[1]: 0);
                    int minSelectedSn = drawObjects.Min(idraw => idraw.GroupParam.FigureSN);

                    //未被选中或者圆以外的图形,大于飞切的最小FigureSN的 加入到变化图形集合(方便做撤销和恢复)
                    int noChange = 0;
                    this.DrawingLayer.Objects.ForEach(idraw =>
                    {
                        if (!drawObjects.Contains(idraw) && idraw.GroupParam.FigureSN > minSelectedSn && !flyArcGroups.Contains(idraw))
                        {
                            drawObjects.Insert(noChange, idraw);
                            NewDrawobjects.Insert(noChange, idraw.Clone());
                            noChange++;
                        }
                    });

                    this.DrawingLayer.DeleteObjects(drawObjects);
                    int sn = this.DrawingLayer.Objects.Count;

                    int idx = 0;
                    NewDrawobjects.ForEach(r =>
                    {
                        r.GroupParam.FigureSN = ++sn;
                    });

                    idx = 0;
                    int baseGroupSN     = GlobalModel.TotalGroupCount;
                    int previousGroupSN = -1;
                    int currentGroupSN  = 0;
                    NewDrawobjects.ForEach(r =>
                    {
                        if (++idx > noChange && r.GroupParam.GroupSN.Count > 1)
                        {
                            if (r.GroupParam.GroupSN[1] == 0)
                            {
                                r.GroupParam.GroupSN.RemoveAt(1);
                            }
                            else
                            {
                                currentGroupSN = baseGroupSN + r.GroupParam.GroupSN[1];
                                r.GroupParam.GroupSN.RemoveAt(1);
                                r.GroupParam.GroupSN.Insert(1, currentGroupSN);
                                if (previousGroupSN != currentGroupSN)
                                {
                                    r.GroupParam.GroupSN[0] = r.GroupParam.FigureSN;
                                }
                                previousGroupSN = currentGroupSN;
                            }
                        }
                    });
                    GlobalModel.TotalGroupCount = GlobalModel.TotalGroupCount + groupCount;
                }

                GlobalModel.TotalDrawObjectCount = GlobalModel.TotalDrawObjectCount + NewDrawobjects.Count;
                this.DrawingLayer.AddObjectOnDrawing(NewDrawobjects);

                if (this.undoRedoBuffer.CanCapture)
                {
                    Circle circle = null;
                    foreach (var item in drawObjects)
                    {
                        circle = item as Circle;
                        if (circle != null)
                        {
                            circle.FlyingCutLeadOut = null;
                        }
                    }
                    drawObjects = drawObjects.OrderBy(c => c.GroupParam.FigureSN).ToList();
                    this.undoRedoBuffer.AddCommand(new EditCommandArcFlyingCut(drawObjects, NewDrawobjects));
                }
                this.UpdateSN();
            }
            else
            {
                ((DrawingLayer)this.DrawingLayer).DeleteObjects(drawObjectsnew);
                foreach (var item in drawObjects)
                {
                    this.DrawingLayer.AddObjectOnRedoUndo(item);
                }
            }
        }