Beispiel #1
0
        /// <summary>
        /// Trims selected entity by the cutting entity. Removes portion of the curve near mouse click.
        /// </summary>
        private void TrimEntity()
        {
            if (firstSelectedEntity == null)
            {
                if (selEntityIndex != -1)
                {
                    firstSelectedEntity = Entities[selEntityIndex];
                    selEntityIndex      = -1;
                    return;
                }
            }
            else if (secondSelectedEntity == null)
            {
                if (selEntityIndex != -1)
                {
                    secondSelectedEntity = Entities[selEntityIndex];
                }
                else
                {
                    DrawSelectionMark(mouseLocation);
                    renderContext.EnableXOR(false);
                    DrawText(mouseLocation.X, (int)Size.Height - mouseLocation.Y + 10, "Select entity to be trimmed",
                             new Font("Tahoma", 8.25f), DrawingColor, ContentAlignment.BottomLeft);
                }
            }

            if (firstSelectedEntity != null && secondSelectedEntity != null)
            {
                if (firstSelectedEntity is ICurve && secondSelectedEntity is ICurve)
                {
                    ICurve trimmingCurve = firstSelectedEntity as ICurve;
                    ICurve curve         = secondSelectedEntity as ICurve;
#if NURBS
                    Point3D[] intersetionPoints = Curve.Intersection(trimmingCurve, curve);
                    if (intersetionPoints.Length > 0 && points.Count > 0)
                    {
                        List <double> parameters = new List <double>();
                        for (int i = 0; i < intersetionPoints.Length; i++)
                        {
                            var    intersetionPoint = intersetionPoints[i];
                            double t = ((InterPoint)intersetionPoint).s;
                            parameters.Add(t);
                        }

                        double distSelected = 1;

                        ICurve[] trimmedCurves = null;
                        if (parameters != null)
                        {
                            parameters.Sort();
                            double u;
                            curve.ClosestPointTo(points[0], out u);
                            distSelected  = Point3D.Distance(points[0], curve.PointAt(u));
                            distSelected += distSelected / 1e3;

                            if (u <= parameters[0])
                            {
                                curve.SplitBy(new Point3D[] { curve.PointAt(parameters[0]) }, out trimmedCurves);
                            }
                            else if (u > parameters[parameters.Count - 1])
                            {
                                curve.SplitBy(new Point3D[] { curve.PointAt(parameters[parameters.Count - 1]) },
                                              out trimmedCurves);
                            }
                            else
                            {
                                for (int i = 0; i < parameters.Count - 1; i++)
                                {
                                    if (u > parameters[i] && u <= parameters[i + 1])
                                    {
                                        curve.SplitBy(
                                            new Point3D[] { curve.PointAt(parameters[i]), curve.PointAt(parameters[i + 1]) },
                                            out trimmedCurves);
                                    }
                                }
                            }
                        }

                        bool success = false;
                        //Decide which portion of curve to be deleted
                        for (int i = 0; i < trimmedCurves.Length; i++)
                        {
                            ICurve trimmedCurve = trimmedCurves[i];
                            double t;

                            trimmedCurve.ClosestPointTo(points[0], out t);
                            {
                                if ((t < trimmedCurve.Domain.t0 || t > trimmedCurve.Domain.t1) ||
                                    Point3D.Distance(points[0], trimmedCurve.PointAt(t)) > distSelected)
                                {
                                    AddAndRefresh((Entity)trimmedCurve, secondSelectedEntity.LayerName);
                                    success = true;
                                }
                            }
                        }

                        // Delete original entity to be trimmed
                        if (success)
                        {
                            Entities.Remove(secondSelectedEntity);
                        }
                    }
                    ClearAllPreviousCommandData();
#endif
                }
            }
        }
Beispiel #2
0
        /// <summary>
        /// Tries to extend entity upto the selected boundary entity. For a short boundary line, it tries to extend selected
        /// entity upto elongated line.
        /// </summary>
        private void ExtendEntity()
        {
            if (firstSelectedEntity == null)
            {
                if (selEntityIndex != -1)
                {
                    firstSelectedEntity = Entities[selEntityIndex];
                    selEntityIndex      = -1;
                    return;
                }
            }
            else if (secondSelectedEntity == null)
            {
                DrawSelectionMark(mouseLocation);

                renderContext.EnableXOR(false);

                DrawText(mouseLocation.X, (int)Size.Height - mouseLocation.Y + 10, "Select entity to extend",
                         new Font("Tahoma", 8.25f), DrawingColor, ContentAlignment.BottomLeft);
            }

            if (secondSelectedEntity == null)
            {
                if (selEntityIndex != -1)
                {
                    secondSelectedEntity = Entities[selEntityIndex];
                }
            }

            if (firstSelectedEntity != null && secondSelectedEntity != null)
            {
                if (firstSelectedEntity is ICurve && secondSelectedEntity is ICurve)
                {
                    ICurve boundary = firstSelectedEntity as ICurve;
                    ICurve curve    = secondSelectedEntity as ICurve;

                    // Check which end of curve is near to boundary
                    double t1, t2;
                    boundary.ClosestPointTo(curve.StartPoint, out t1);
                    boundary.ClosestPointTo(curve.EndPoint, out t2);

                    Point3D projStartPt = boundary.PointAt(t1);
                    Point3D projEndPt   = boundary.PointAt(t2);

                    double curveStartDistance = curve.StartPoint.DistanceTo(projStartPt);
                    double curveEndDistance   = curve.EndPoint.DistanceTo(projEndPt);

                    bool success = false;
                    if (curveStartDistance < curveEndDistance)
                    {
                        if (curve is Line)
                        {
                            success = ExtendLine(curve, boundary, true);
                        }
                        else if (curve is LinearPath)
                        {
                            success = ExtendPolyLine(curve, boundary, true);
                        }
                        else if (curve is Arc)
                        {
                            success = ExtendCircularArc(curve, boundary, true);
                        }
                        else if (curve is EllipticalArc)
                        {
                            success = ExtendEllipticalArc(curve, boundary, true);
                        }
#if NURBS
                        else if (curve is Curve)
                        {
                            success = ExtendSpline(curve, boundary, true);
                        }
#endif
                    }
                    else
                    {
                        if (curve is Line)
                        {
                            success = ExtendLine(curve, boundary, false);
                        }
                        else if (curve is LinearPath)
                        {
                            success = ExtendPolyLine(curve, boundary, false);
                        }
                        else if (curve is Arc)
                        {
                            success = ExtendCircularArc(curve, boundary, false);
                        }
                        else if (curve is EllipticalArc)
                        {
                            success = ExtendEllipticalArc(curve, boundary, false);
                        }
#if NURBS
                        else if (curve is Curve)
                        {
                            success = ExtendSpline(curve, boundary, false);
                        }
#endif
                    }
                    if (success)
                    {
                        Entities.Remove(secondSelectedEntity);
                        Entities.Regen();
                    }
                }
                ClearAllPreviousCommandData();
            }
        }