Ejemplo n.º 1
0
        // Extends input line upto the provided boundary.
        private bool ExtendLine(ICurve lineCurve, ICurve boundary, bool nearStart)
        {
            Line line = lineCurve as Line;

            // Create temp line which will intersect boundary curve depending on which end to extend
            Line     tempLine  = null;
            Vector3D direction = null;

            if (nearStart)
            {
                tempLine  = new Line(line.StartPoint, line.StartPoint);
                direction = new Vector3D(line.EndPoint, line.StartPoint);
            }
            else
            {
                tempLine  = new Line(line.EndPoint, line.EndPoint);
                direction = new Vector3D(line.StartPoint, line.EndPoint);
            }
            direction.Normalize();
            tempLine.EndPoint = tempLine.EndPoint + direction * extensionLength;
#if NURBS
            // Get intersection points for input line and boundary
            // If not intersecting and boundary is line, we can try with extended boundary
            Point3D[] intersetionPoints = Curve.Intersection(boundary, tempLine);
            if (intersetionPoints.Length == 0)
            {
                intersetionPoints = Curve.Intersection(GetExtendedBoundary(boundary), tempLine);
            }

            // Modify line start/end point as closest intersection point
            if (intersetionPoints.Length > 0)
            {
                if (nearStart)
                {
                    line.StartPoint = GetClosestPoint(line.StartPoint, intersetionPoints);
                }
                else
                {
                    line.EndPoint = GetClosestPoint(line.EndPoint, intersetionPoints);
                }
                AddAndRefresh((Entity)line.Clone(), ((Entity)lineCurve).LayerName);
                return(true);
            }
#endif
            return(false);
        }
Ejemplo n.º 2
0
            protected override void WorkCompleted(Environment model)
            {
                model.Entities.Add(toolPath, "Default", Color.DarkBlue);

                #region Tool symbol definition

                Block b1 = new Block("ballTool");

                Circle c1 = new Circle(0, 0, 0, ballToolRadius);
                Circle c2 = new Circle(0, 0, 50, ballToolRadius);
                Arc    a1 = new Arc(0, 0, 0, ballToolRadius, Math.PI, 2 * Math.PI);
                a1.Rotate(Math.PI / 2, Vector3D.AxisX);
                Arc a2 = (Arc)a1.Clone();
                a2.Rotate(Math.PI / 2, Vector3D.AxisZ);

                Line l1 = new Line(-ballToolRadius, 0, 0, -ballToolRadius, 0, 50);

                b1.Entities.Add(c1);
                b1.Entities.Add(c2);
                b1.Entities.Add(a1);
                b1.Entities.Add(a2);
                b1.Entities.Add(l1);

                LinearPath lp1 = LinearPath.CreateHelix(ballToolRadius, 50, 1, false, .1);
                b1.Entities.Add(lp1);

                b1.Entities.Add(lp1);
                for (int i = 1; i < 4; i++)
                {
                    Line cloneLn = (Line)l1.Clone();
                    cloneLn.Rotate(i * Math.PI / 2, Vector3D.AxisZ);
                    b1.Entities.Add(cloneLn);
                }

                model.Blocks.Add(b1);

                #endregion

                // Adds a reference to the tool symbol
                model.Entities.Add(new BlockReference(toolPath.Vertices[toolPath.Vertices.Length - 1], "ballTool", 1, 1, 1, 0));

                model.ZoomFit();
            }
Ejemplo n.º 3
0
        protected override void OnMouseDown(MouseButtonEventArgs e)
        {
            var mousePos = RenderContextUtility.ConvertPoint(GetMousePosition(e));

            this.selEntityIndex = GetEntityUnderMouseCursor(mousePos);

            if (waitingForSelection)
            {
                if (this.selEntityIndex != -1)
                {
                    if (selEntity == null || drawingAngularDim)
                    {
                        this.selEntity = this.Entities[selEntityIndex];
                        if (activeOperationLabel != "")
                        {
                            this.selEntity.Selected = true;
                        }
                    }

                    // drawingAngularDim from lines needs more than one selection
                    if (!drawingAngularDim || this.Entities[selEntityIndex] is Arc)
                    {
                        waitingForSelection = false;
                    }
                }
            }

            if (GetToolBar().Contains(mousePos))
            {
                base.OnMouseDown(e);

                return;
            }

            #region Handle LMB Clicks
            if (ActionMode == actionType.None && e.ChangedButton == MouseButton.Left)
            {
                // we need to skip adding points for entity selection click
                editingMode = doingOffset || doingMirror || doingExtend || doingTrim || doingFillet || doingChamfer || doingTangents;

                ScreenToPlane(mousePos, plane, out current);

                if (objectSnapEnabled && snapPoint != null)
                {
                    if (!(editingMode && firstClick))
                    {
                        points.Add(snapPoint);
                    }
                }
                else if (IsPolygonClosed())//control needed to close curve and polyline when cursor is near the starting point of polyline or curve
                {
                    //if the distance from current point and first point stored is less than given threshold
                    points.Add((Point3D)points[0].Clone()); //the point to add to points is the first point stored.
                    current = (Point3D)points[0].Clone();
                }
                else if (gridSnapEnabled)
                {
                    if (!(editingMode && firstClick))
                    {
                        SnapToGrid(ref current);
                        points.Add(current);
                    }
                }
                else
                {
                    if (!(editingMode && firstClick))
                    {
                        points.Add(current);
                    }
                }
                firstClick = false;

                // If drawing points, create and add new point entity on each LMB click
                if (drawingPoints)
                {
                    devDept.Eyeshot.Entities.Point point;

                    if (objectSnapEnabled && snapPoint != null)
                    {
                        point = new devDept.Eyeshot.Entities.Point(snap);
                    }
                    else
                    {
                        point = new devDept.Eyeshot.Entities.Point(current);
                    }

                    AddAndRefresh(point, ActiveLayerName);
                }
                else if (drawingText)
                {
                    devDept.Eyeshot.Entities.Text text = new Text(current, "Sample Text", 5);
                    AddAndRefresh(text, ActiveLayerName);
                }
                else if (drawingLeader)
                {
                    if (points.Count == 3)
                    {
                        Leader leader = new Leader(Plane.XY, points);
                        leader.ArrowheadSize = 3;
                        AddAndRefresh(leader, ActiveLayerName);
                        devDept.Eyeshot.Entities.Text text = new Text((Point3D)current.Clone(), "Sample Text", leader.ArrowheadSize);
                        AddAndRefresh(text, ActiveLayerName);

                        drawingLeader = false;
                    }
                }
                // If LINE drawing is finished, create and add line entity to model
                else if (drawingLine && points.Count == 2)
                {
                    Line line = new Line(points[0], points[1]);
                    AddAndRefresh(line, ActiveLayerName);
                    drawingLine = false;
                }
                // If CIRCLE drawing is finished, create and add a circle entity to model
                else if (drawingCircle && points.Count == 2)
                {
                    Circle circle = new Circle(drawingPlane, drawingPlane.Origin, radius);
                    AddAndRefresh(circle, ActiveLayerName);

                    drawingCircle = false;
                }
                // If ARC drawing is finished, create and add an arc entity to model
                // Input - Center and two end points
                else if (drawingArc && points.Count == 3)
                {
                    Arc arc = new Arc(drawingPlane, drawingPlane.Origin, radius, 0, arcSpanAngle);
                    AddAndRefresh(arc, ActiveLayerName);

                    drawingArc = false;
                }
                // If drawing ellipse, create and add ellipse entity to model
                // Inputs - Ellipse center, End of first axis, End of second axis
                else if (drawingEllipse && points.Count == 3)
                {
                    Ellipse ellipse = new Ellipse(drawingPlane, drawingPlane.Origin, radius, radiusY);
                    AddAndRefresh(ellipse, ActiveLayerName);

                    drawingEllipse = false;
                }
                // If EllipticalArc drawing is finished, create and add EllipticalArc entity to model
                // Input - Ellipse center, End of first axis, End of second axis, end point
                else if (drawingEllipticalArc && points.Count == 4)
                {
                    EllipticalArc ellipticalArc = new EllipticalArc(drawingPlane, drawingPlane.Origin, radius, radiusY, 0, arcSpanAngle, true);
                    AddAndRefresh(ellipticalArc, ActiveLayerName);

                    drawingEllipticalArc = false;
                }
                else if (drawingLinearDim && points.Count == 3)
                {
                    LinearDim linearDim = new LinearDim(drawingPlane, points[0], points[1], current, dimTextHeight);
                    AddAndRefresh(linearDim, ActiveLayerName);

                    drawingLinearDim = false;
                }
                else if (drawingAlignedDim && points.Count == 3)
                {
                    LinearDim alignedDim = new LinearDim(drawingPlane, points[0], points[1], current, dimTextHeight);
                    AddAndRefresh(alignedDim, ActiveLayerName);

                    drawingAlignedDim = false;
                }
                else if (drawingOrdinateDim && points.Count == 2)
                {
                    OrdinateDim ordinateDim = new OrdinateDim(Plane.XY, points[0], points[1], drawingOrdinateDimVertical, dimTextHeight);
                    AddAndRefresh(ordinateDim, ActiveLayerName);

                    drawingOrdinateDim = false;
                }
                else if ((drawingRadialDim || drawingDiametricDim) && points.Count == 2)
                {
                    if (selEntity is Circle)
                    {
                        Circle circle = selEntity as Circle;

                        // ensures that radialDim plane has always the correct normal
                        Circle orientedCircle = new Circle(Plane.XY, circle.Center, circle.Radius);

                        if (drawingRadialDim)
                        {
                            RadialDim radialDim = new RadialDim(orientedCircle, points[points.Count - 1], dimTextHeight);
                            AddAndRefresh(radialDim, ActiveLayerName);
                            drawingRadialDim = false;
                        }
                        else
                        {
                            DiametricDim diametricDim = new DiametricDim(orientedCircle, points[points.Count - 1], dimTextHeight);
                            AddAndRefresh(diametricDim, ActiveLayerName);
                            drawingDiametricDim = false;
                        }
                    }
                }
                else if (drawingAngularDim)
                {
                    if (!drawingAngularDimFromLines)
                    {
                        if (selEntity is Arc && points.Count == 2 && !drawingQuadrantPoint)
                        {
                            Arc     arc        = selEntity as Arc;
                            Plane   myPlane    = (Plane)arc.Plane.Clone();
                            Point3D startPoint = arc.StartPoint;
                            Point3D endPoint   = arc.EndPoint;

                            // checks if the Arc is clockwise
                            if (Utility.IsOrientedClockwise(arc.Vertices))
                            {
                                myPlane.Flip();
                                startPoint = arc.EndPoint;
                                endPoint   = arc.StartPoint;
                            }

                            AngularDim angularDim = new AngularDim(myPlane, startPoint, endPoint, points[points.Count - 1], dimTextHeight);

                            angularDim.TextSuffix = "°";

                            AddAndRefresh(angularDim, ActiveLayerName);
                            drawingAngularDim = false;
                        }
                    }

                    // If it's not time to set quadrantPoint, adds the lines for angular dim
                    if (selEntity is Line && !drawingQuadrantPoint && quadrantPoint == null)
                    {
                        Line selectedLine = (Line)selEntity;

                        if (firstLine == null)
                        {
                            firstLine = selectedLine;
                        }
                        else if (secondLine == null && !ReferenceEquals(firstLine, selectedLine))
                        {
                            secondLine           = selectedLine;
                            drawingQuadrantPoint = true;
                            // resets points to get only the quadrant point and text position point
                            points.Clear();
                        }

                        drawingAngularDimFromLines = true;
                    }
                    else if (drawingQuadrantPoint)
                    {
                        ScreenToPlane(mousePos, plane, out quadrantPoint);
                        drawingQuadrantPoint = false;
                    }
                    //if all parameters are present, gets angular dim
                    else if (points.Count == 2 && quadrantPoint != null)
                    {
                        AngularDim angularDim = new AngularDim(plane, (Line)firstLine.Clone(), (Line)secondLine.Clone(), quadrantPoint, points[points.Count - 1], dimTextHeight);

                        angularDim.TextSuffix = "°";

                        AddAndRefresh(angularDim, ActiveLayerName);

                        drawingAngularDim          = false;
                        drawingAngularDimFromLines = false;
                    }
                }
                else if (doingOffset && points.Count == 1)
                {
                    CreateOffsetEntity();
                    ClearAllPreviousCommandData();
                }
                else if (doingMirror && points.Count == 2 && selEntity != null)
                {
                    CreateMirrorEntity();
                    ClearAllPreviousCommandData();
                }
                else if (doingExtend && firstSelectedEntity != null && secondSelectedEntity != null)
                {
                    ExtendEntity();
                    ClearAllPreviousCommandData();
                }
                else if (doingTrim && firstSelectedEntity != null && secondSelectedEntity != null)
                {
                    TrimEntity();
                    ClearAllPreviousCommandData();
                }
                else if (doingFillet && firstSelectedEntity != null && secondSelectedEntity != null)
                {
                    CreateFilletEntity();
                    ClearAllPreviousCommandData();
                }
                else if (doingChamfer && firstSelectedEntity != null && secondSelectedEntity != null)
                {
                    CreateChamferEntity();
                    ClearAllPreviousCommandData();
                }
                else if (doingTangents && firstSelectedEntity != null && secondSelectedEntity != null)
                {
                    CreateTangentEntity();
                    ClearAllPreviousCommandData();
                }
                else if (doingMove && points.Count == 2)
                {
                    if (points.Count == 2)
                    {
                        foreach (Entity ent in this.selEntities)
                        {
                            Vector3D movement = new Vector3D(points[0], points[1]);
                            ent.Translate(movement);
                        }

                        Entities.Regen();
                        ClearAllPreviousCommandData();
                    }
                }
                else if (doingRotate)
                {
                    if (points.Count == 3)
                    {
                        foreach (Entity ent in this.selEntities)
                        {
                            ent.Rotate(arcSpanAngle, Vector3D.AxisZ, points[0]);
                        }

                        Entities.Regen();
                        ClearAllPreviousCommandData();
                    }
                }
                else if (doingScale)
                {
                    if (points.Count == 3)
                    {
                        foreach (Entity ent in this.selEntities)
                        {
                            ent.Scale(points[0], scaleFactor);
                        }

                        Entities.Regen();
                        ClearAllPreviousCommandData();
                    }
                }
            }
            #endregion

            #region Handle RMB Clicks
            else if (e.ChangedButton == MouseButton.Right)
            {
                ScreenToPlane(mousePos, plane, out current);

                if (drawingPoints)
                {
                    points.Clear();
                    drawingPoints = false;
                }
                else if (drawingText)
                {
                    drawingText = false;
                }
                else if (drawingLeader)
                {
                    drawingLeader = false;
                }

                // If drawing polyline, create and add LinearPath entity to model
                else if (drawingPolyLine)
                {
                    LinearPath lp = new LinearPath(points);
                    AddAndRefresh(lp, ActiveLayerName);

                    drawingPolyLine = false;
                }
                // If drawing spline, create and add curve entity to model
                else if (drawingCurve)
                {
#if NURBS
                    Curve curve = Curve.CubicSplineInterpolation(points);
                    AddAndRefresh(curve, ActiveLayerName);
#endif
                    drawingCurve = false;
                }
                else
                {
                    ClearAllPreviousCommandData();
                }
            }
            #endregion

            base.OnMouseDown(e);
        }