Ejemplo n.º 1
0
        public bool SetStartMovePoint(UnitPoint unitPoint)
        {
            float thresholdWidth = UCCanvas.GetThresholdWidth();

            if (this.PointInObject(unitPoint))
            {
                if (HitUtil.IsPointInLine(this.LeftTopPoint, this.RightTopPoint, unitPoint, thresholdWidth))
                {
                    unitPoint              = this.HandleSideBoundError(unitPoint, LeftTopPoint, RightTopPoint, thresholdWidth);
                    this.StartMovePoint    = HitUtil.FindApparentIntersectPoint(this.CenterPoint, unitPoint, this.LeftTopPoint, this.RightTopPoint);
                    this.StartMovePosition = NodePosition.LeftTop;
                }
                else if (HitUtil.IsPointInLine(this.RightTopPoint, this.RightBottomPoint, unitPoint, thresholdWidth))
                {
                    unitPoint              = this.HandleSideBoundError(unitPoint, RightTopPoint, RightBottomPoint, thresholdWidth);
                    this.StartMovePoint    = HitUtil.FindApparentIntersectPoint(this.CenterPoint, unitPoint, this.RightTopPoint, this.RightBottomPoint);
                    this.StartMovePosition = NodePosition.RightTop;
                }
                else if (HitUtil.IsPointInLine(this.RightBottomPoint, this.LeftBottomPoint, unitPoint, thresholdWidth))
                {
                    unitPoint              = this.HandleSideBoundError(unitPoint, RightBottomPoint, LeftBottomPoint, thresholdWidth);
                    this.StartMovePoint    = HitUtil.FindApparentIntersectPoint(this.CenterPoint, unitPoint, this.RightBottomPoint, this.LeftBottomPoint);
                    this.StartMovePosition = NodePosition.RightBottom;
                }
                else if (HitUtil.IsPointInLine(this.LeftBottomPoint, this.LeftTopPoint, unitPoint, thresholdWidth))
                {
                    unitPoint              = this.HandleSideBoundError(unitPoint, LeftBottomPoint, LeftTopPoint, thresholdWidth);
                    this.StartMovePoint    = HitUtil.FindApparentIntersectPoint(this.CenterPoint, unitPoint, this.LeftBottomPoint, this.LeftTopPoint);
                    this.StartMovePosition = NodePosition.LeftBottom;
                }
                this.OverCutting();
                return(true);
            }
            return(false);
        }
Ejemplo n.º 2
0
 public bool SetStartMovePoint(UnitPoint unitPoint)
 {
     if (this.PointInObject2(ref unitPoint))
     {
         if (this.StartMovePointIndex != this.SideCount - 1)
         {
             this.startMovePoint = HitUtil.FindApparentIntersectPoint(this.centerPoint, unitPoint, this.hexagonPoints[this.StartMovePointIndex], this.hexagonPoints[this.StartMovePointIndex + 1]);
         }
         else
         {
             this.startMovePoint = HitUtil.FindApparentIntersectPoint(this.centerPoint, unitPoint, this.hexagonPoints[this.StartMovePointIndex], this.hexagonPoints[0]);
         }
         this.OverCutting();
         return(true);
     }
     return(false);
 }
Ejemplo n.º 3
0
        private void SetNewStartMovePoint()
        {
            double cloneStartAngle     = HitUtil.LineAngleR(this.clone.CenterPoint, this.clone.HexagonPoints[0], 0);
            double offsetAngle         = cloneStartAngle - HitUtil.LineAngleR(this.owner.CenterPoint, this.owner.HexagonPoints[0], 0);
            double cloneStartMoveAngle = HitUtil.LineAngleR(this.owner.CenterPoint, this.owner.StartMovePoint, 0) + offsetAngle;

            if (cloneStartMoveAngle > 2 * Math.PI)
            {
                cloneStartMoveAngle -= 2 * Math.PI;
            }
            else if (cloneStartMoveAngle < 0)
            {
                cloneStartMoveAngle += 2 * Math.PI;
            }
            this.clone.StartMovePoint = HitUtil.PointOnCircle(this.clone.CenterPoint, this.clone.GetRadius(this.clone.HexagonPoints[0]), cloneStartMoveAngle);
            if (this.owner.StartMovePointIndex != this.owner.HexagonPoints.Length - 1)
            {
                this.clone.StartMovePoint = HitUtil.FindApparentIntersectPoint(this.clone.CenterPoint, this.clone.StartMovePoint, this.clone.HexagonPoints[this.owner.StartMovePointIndex], this.clone.HexagonPoints[this.owner.StartMovePointIndex + 1]);
            }
            else
            {
                this.clone.StartMovePoint = HitUtil.FindApparentIntersectPoint(this.clone.CenterPoint, this.clone.StartMovePoint, this.clone.HexagonPoints[this.owner.StartMovePointIndex], this.clone.HexagonPoints[0]);
            }
        }
Ejemplo n.º 4
0
        private void GetMultiLineLeadLineParams(IDrawObject drawObject, LineInOutParamsModel leadInOutParamsModel)
        {
            MultiSegmentLineBase multiSegmentLine = drawObject as MultiSegmentLineBase;
            int segment = 0;

            if (multiSegmentLine != null)
            {
                //所在段数必须合法
                segment = DrawingOperationHelper.GetPointInLineIndex(multiSegmentLine, this.p2);
                int nextIndex = (segment + 1 >= multiSegmentLine.PointCount && multiSegmentLine.IsCloseFigure) ? 0 : segment + 1;
                if (double.IsNaN(multiSegmentLine.Points[segment].Bulge))
                {
                    double partLen = HitUtil.Distance(multiSegmentLine.Points[segment].Point, this.p2);
                    double allLen  = HitUtil.Distance(multiSegmentLine.Points[segment].Point, multiSegmentLine.Points[nextIndex].Point);
                    float  percent = (float)(segment + partLen / allLen);
                    leadInOutParamsModel.FigureTotalLength = (float)(DrawingOperationHelper.GetLengthByPositionInPolyLine(multiSegmentLine.Points, multiSegmentLine.IsCloseFigure, percent) / multiSegmentLine.SizeLength);
                    //角度(p1p2与当前线段所成夹角或与圆弧在当前鼠标点位置的切点出的切线所成夹角)
                    this.p2 = HitUtil.FindApparentIntersectPoint(this.p1, this.p2, multiSegmentLine.Points[segment].Point, multiSegmentLine.Points[nextIndex].Point);
                    double    lineAngle          = HitUtil.LineAngleR(multiSegmentLine.Points[nextIndex].Point, multiSegmentLine.Points[segment].Point, 0);
                    UnitPoint extensionCordPoint = HitUtil.LineEndPoint(multiSegmentLine.Points[segment].Point, lineAngle, 5);
                    leadInOutParamsModel.LineInAngle = (float)BulgeHelper.CalTwoLinesAngleFromThreePoints(extensionCordPoint, this.p2, this.p1);
                    multiSegmentLine.IsInnerCut      = HitUtil.IsClockwiseByCross(this.p1, this.p2, extensionCordPoint) == multiSegmentLine.Clockwise ? false : true;
                }
                else
                {
                    ArcModelMini arcModelMini = DrawingOperationHelper.GetArcParametersFromBulge(multiSegmentLine.Points[segment].Point, multiSegmentLine.Points[nextIndex].Point, (float)multiSegmentLine.Points[segment].Bulge);
                    float        percent      = segment + DrawingOperationHelper.GetPercentInArcByPoint(arcModelMini, this.p2);
                    leadInOutParamsModel.FigureTotalLength = (float)(DrawingOperationHelper.GetLengthByPositionInPolyLine(multiSegmentLine.Points, multiSegmentLine.IsCloseFigure, percent) / multiSegmentLine.SizeLength);
                    bool isInner;
                    leadInOutParamsModel.LineInAngle = DrawingOperationHelper.GetLeadLineAngleArc(this.p1, this.p2, arcModelMini.Center, arcModelMini.Clockwise, out isInner);
                    multiSegmentLine.IsInnerCut      = isInner;
                }
            }
            //长度(p1p2的长度)
            leadInOutParamsModel.LineInLength = (float)HitUtil.Distance(p1, p2);
        }
Ejemplo n.º 5
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="canvas"></param>
        /// <param name="point"></param>
        /// <param name="snappoint"></param>
        /// <returns></returns>
        public eDrawObjectMouseDown OnMouseDown(ICanvas canvas, UnitPoint point, ISnapPoint snappoint)
        {
            List <IDrawObject>    drawitems = canvas.DataModel.GetHitObjects(canvas, point);
            List <DrawTools.Line> lines     = GetLines(drawitems);

            // add to source lines
            if (m_originalLines.Count == 0 || Control.ModifierKeys == Keys.Shift)
            {
                foreach (DrawTools.Line line in lines)
                {
                    AddLine(point, line);
                }
                SetSelectHint();
                return(eDrawObjectMouseDown.Continue);
            }

            if (m_originalLines.Count == 0 || Control.ModifierKeys == Keys.Control)
            {
                foreach (DrawTools.Line line in lines)
                {
                    if (m_originalLines.ContainsKey(line))
                    {
                        RemoveLine(line);
                    }
                    else
                    {
                        AddLine(point, line);
                    }
                }
                SetSelectHint();
                return(eDrawObjectMouseDown.Continue);
            }

            if (drawitems.Count == 0)
            {
                return(eDrawObjectMouseDown.Continue);
            }

            // all lines have been added, now find edge to where to extend
            if (drawitems[0] is DrawTools.Line)
            {
                DrawTools.Line edge     = (DrawTools.Line)drawitems[0];
                bool           modified = false;
                foreach (LinePoints originalLp in m_originalLines.Values)
                {
                    UnitPoint intersectpoint = HitUtil.LinesIntersectPoint(edge.P1, edge.P2, originalLp.Line.P1, originalLp.Line.P2);
                    // lines intersect so shrink line
                    if (intersectpoint != UnitPoint.Empty)
                    {
                        LinePoints lp = new LinePoints();
                        lp.SetLine(originalLp.Line);
                        lp.MousePoint = originalLp.MousePoint;
                        m_modifiedLines.Add(lp.Line, lp);
                        lp.SetNewPoints(lp.Line, lp.MousePoint, intersectpoint);
                        modified = true;
                        continue;
                    }
                    // lines do not intersect, find apparent intersect point on existing edge line
                    if (intersectpoint == UnitPoint.Empty)
                    {
                        UnitPoint apprarentISPoint = HitUtil.FindApparentIntersectPoint(
                            edge.P1,
                            edge.P2,
                            originalLp.Line.P1,
                            originalLp.Line.P2,
                            false,
                            true);
                        if (apprarentISPoint == UnitPoint.Empty)
                        {
                            continue;
                        }

                        modified = true;
                        originalLp.Line.ExtendLineToPoint(apprarentISPoint);

                        LinePoints lp = new LinePoints();
                        lp.SetLine(originalLp.Line);
                        lp.MousePoint = point;
                        m_modifiedLines.Add(lp.Line, lp);
                    }
                }
                if (modified)
                {
                    canvas.DataModel.AfterEditObjects(this);
                }
                return(eDrawObjectMouseDown.Done);
            }

            if (drawitems[0] is DrawTools.Arc)
            {
                DrawTools.Arc edge = (DrawTools.Arc)drawitems[0];
                foreach (LinePoints originalLp in m_originalLines.Values)
                {
                }
                bool modified = false;
            }
            return(eDrawObjectMouseDown.Done);
        }
Ejemplo n.º 6
0
        public eDrawObjectMouseDown OnMouseDown(ICanvas canvas, UnitPoint point, ISnapPoint snappoint)
        {
            List <IDrawObject> items = canvas.DataModel.GetHitObjects(canvas, point);

            DrawTools.Line line = null;
            // find first line
            foreach (IDrawObject item in items)
            {
                if (item is DrawTools.Line)
                {
                    line = item as DrawTools.Line;
                    if (line != m_l1Original.Line)
                    {
                        break;
                    }
                }
            }
            if (line == null)
            {
                if (m_l1Original.Line == null)
                {
                    SetHint("No line selected. Select first line");
                }
                else
                {
                    SetHint("No line selected. Select second line");
                }
                return(eDrawObjectMouseDown.Continue);
            }
            if (m_l1Original.Line == null)
            {
                line.Highlighted = true;
                m_l1Original.SetLine(line);
                m_l1Original.MousePoint = point;
                SetHint("Select second line");
                return(eDrawObjectMouseDown.Continue);
            }
            if (m_l2Original.Line == null)
            {
                line.Highlighted = true;
                m_l2Original.SetLine(line);
                m_l2Original.MousePoint = point;

                UnitPoint intersectpoint = HitUtil.LinesIntersectPoint(
                    m_l1Original.Line.P1,
                    m_l1Original.Line.P2,
                    m_l2Original.Line.P1,
                    m_l2Original.Line.P2);

                // if lines do not intersect then extend lines to intersect point
                if (intersectpoint == UnitPoint.Empty)
                {
                    UnitPoint apprarentISPoint = HitUtil.FindApparentIntersectPoint(m_l1Original.Line.P1, m_l1Original.Line.P2, m_l2Original.Line.P1, m_l2Original.Line.P2);
                    if (apprarentISPoint == UnitPoint.Empty)
                    {
                        return(eDrawObjectMouseDown.Done);
                    }
                    m_l1Original.Line.ExtendLineToPoint(apprarentISPoint);
                    m_l2Original.Line.ExtendLineToPoint(apprarentISPoint);
                    m_l1NewPoint.SetLine(m_l1Original.Line);
                    m_l2NewPoint.SetLine(m_l2Original.Line);
                    canvas.DataModel.AfterEditObjects(this);
                    return(eDrawObjectMouseDown.Done);
                }

                m_l1NewPoint.SetNewPoints(m_l1Original.Line, m_l1Original.MousePoint, intersectpoint);
                m_l2NewPoint.SetNewPoints(m_l2Original.Line, m_l2Original.MousePoint, intersectpoint);
                canvas.DataModel.AfterEditObjects(this);
                return(eDrawObjectMouseDown.Done);
            }
            return(eDrawObjectMouseDown.Done);
        }
Ejemplo n.º 7
0
        public eDrawObjectMouseDownEnum OnMouseDown(ICanvas canvas, UnitPoint point, ISnapPoint snappoint)
        {
            try
            {
                List <IDrawObject> items = canvas.DataModel.GetHitObjects(canvas, point);
                DrawTools.LineTool line  = null;
                foreach (IDrawObject item in items)
                {
                    if (item is DrawTools.LineTool)
                    {
                        line = item as DrawTools.LineTool;
                        if (line.Type == DrawTools.LineType.PointLine)
                        {
                            return(eDrawObjectMouseDownEnum.Done);
                        }
                        if (line != m_l1Original.Line)
                        {
                            break;
                        }
                    }
                }
                if (line == null)
                {
                    if (m_l1Original.Line == null)
                    {
                        SetHint("请选择第一个直线");
                    }
                    else
                    {
                        SetHint("请选择第二个直线");
                    }
                    return(eDrawObjectMouseDownEnum.Continue);
                }
                if (m_l1Original.Line == null)
                {
                    line.Highlighted = true;
                    m_l1Original.SetLine(line);
                    m_l1Original.MousePoint = point;
                    SetHint("请选择第二个直线");
                    return(eDrawObjectMouseDownEnum.Continue);
                }
                if (m_l2Original.Line == null)
                {
                    line.Highlighted = true;
                    m_l2Original.SetLine(line);
                    m_l2Original.MousePoint = point;

                    UnitPoint intersectpoint = HitUtil.LinesIntersectPoint(
                        m_l1Original.Line.P1,
                        m_l1Original.Line.P2,
                        m_l2Original.Line.P1,
                        m_l2Original.Line.P2);

                    //如果两条实现没有相交,则将两条直线延长到交点
                    if (intersectpoint == UnitPoint.Empty)
                    {
                        UnitPoint apprarentISPoint = HitUtil.FindApparentIntersectPoint(m_l1Original.Line.P1, m_l1Original.Line.P2, m_l2Original.Line.P1, m_l2Original.Line.P2);
                        if (apprarentISPoint == UnitPoint.Empty)
                        {
                            return(eDrawObjectMouseDownEnum.Done);
                        }
                        m_l1Original.Line.ExtendLineToPoint(apprarentISPoint);
                        m_l2Original.Line.ExtendLineToPoint(apprarentISPoint);
                        m_l1NewPoint.SetLine(m_l1Original.Line);
                        m_l2NewPoint.SetLine(m_l2Original.Line);
                        canvas.DataModel.AfterEditObjects(this);
                        return(eDrawObjectMouseDownEnum.Done);
                    }

                    m_l1NewPoint.SetNewPoints(m_l1Original.Line, m_l1Original.MousePoint, intersectpoint);
                    m_l2NewPoint.SetNewPoints(m_l2Original.Line, m_l2Original.MousePoint, intersectpoint);
                    canvas.DataModel.AfterEditObjects(this);
                    return(eDrawObjectMouseDownEnum.Done);
                }
                return(eDrawObjectMouseDownEnum.Done);
            }
            catch (Exception ex)
            { throw ex; }
        }
Ejemplo n.º 8
0
        public eDrawObjectMouseDownEnum OnMouseDown(ICanvas canvas, UnitPoint point, ISnapPoint snappoint)
        {
            try
            {
                List <IDrawObject>        drawitems = canvas.DataModel.GetHitObjects(canvas, point);
                List <DrawTools.LineTool> lines     = GetLines(drawitems);
                if (m_originalLines.Count == 0 || Control.ModifierKeys == Keys.Shift)
                {
                    foreach (DrawTools.LineTool line in lines)
                    {
                        AddLine(point, line);
                    }
                    SetSelectHint();
                    return(eDrawObjectMouseDownEnum.Continue);
                }
                if (m_originalLines.Count == 0 || Control.ModifierKeys == Keys.Control)
                {
                    foreach (DrawTools.LineTool line in lines)
                    {
                        if (m_originalLines.ContainsKey(line))
                        {
                            RemoveLine(line);
                        }
                        else
                        {
                            AddLine(point, line);
                        }
                    }
                    SetSelectHint();
                    return(eDrawObjectMouseDownEnum.Continue);
                }

                if (drawitems.Count == 0)
                {
                    return(eDrawObjectMouseDownEnum.Continue);
                }

                if (drawitems[0] is DrawTools.LineTool)
                {
                    DrawTools.LineTool edge = (DrawTools.LineTool)drawitems[0];
                    if (edge.Type == DrawTools.LineType.PointLine)
                    {
                        return(eDrawObjectMouseDownEnum.Done);
                    }
                    bool modified = false;
                    foreach (LinePoints originalLp in m_originalLines.Values)
                    {
                        UnitPoint intersectpoint = HitUtil.LinesIntersectPoint(edge.P1, edge.P2, originalLp.Line.P1, originalLp.Line.P2);
                        if (intersectpoint != UnitPoint.Empty)
                        {
                            LinePoints lp = new LinePoints();
                            lp.SetLine(originalLp.Line);
                            lp.MousePoint = originalLp.MousePoint;
                            m_modifiedLines.Add(lp.Line, lp);
                            lp.SetNewPoints(lp.Line, lp.MousePoint, intersectpoint);
                            modified = true;
                            continue;
                        }
                        if (intersectpoint == UnitPoint.Empty)
                        {
                            UnitPoint apprarentISPoint = HitUtil.FindApparentIntersectPoint(
                                edge.P1,
                                edge.P2,
                                originalLp.Line.P1,
                                originalLp.Line.P2,
                                false,
                                true);
                            if (apprarentISPoint == UnitPoint.Empty)
                            {
                                continue;
                            }

                            modified = true;
                            originalLp.Line.ExtendLineToPoint(apprarentISPoint);

                            LinePoints lp = new LinePoints();
                            lp.SetLine(originalLp.Line);
                            lp.MousePoint = point;
                            m_modifiedLines.Add(lp.Line, lp);
                        }
                    }
                    if (modified)
                    {
                        canvas.DataModel.AfterEditObjects(this);
                    }
                    return(eDrawObjectMouseDownEnum.Done);
                }
                return(eDrawObjectMouseDownEnum.Done);
            }
            catch (Exception ex)
            { throw ex; }
        }