public void PointOnLineMidpoint()
        {
            var sketch = Sketch.Create();
            var p1     = sketch.AddPoint(new Pnt2d(3, -10));
            var p2     = sketch.AddPoint(new Pnt2d(3, 10));
            var line   = new SketchSegmentLine(p1, p2);
            var s1     = sketch.AddSegment(line);
            var p3     = sketch.AddPoint(new Pnt2d(-5, -5));
            var p4     = sketch.AddPoint(new Pnt2d(20, 20));
            var s2     = sketch.AddSegment(new SketchSegmentLine(p3, p4));
            var c1     = sketch.AddConstraint(new SketchConstraintPointOnMidpoint(p3, s1));

            Assert.IsTrue(sketch.SolveConstraints(true));
            var pointOnCurve = new Geom2dAPI_ProjectPointOnCurve(sketch.Points[p3], line.MakeCurve(sketch.Points));

            Assert.AreEqual(1, pointOnCurve.NbPoints());
            Assert.AreEqual(0.0, pointOnCurve.Distance(1), MaxLengthDelta);

            sketch.Points[p3] = new Pnt2d(18, 18);
            Assert.IsTrue(sketch.SolveConstraints(true));
            pointOnCurve = new Geom2dAPI_ProjectPointOnCurve(sketch.Points[p3], new Geom2d_Line(line.GetLine(sketch.Points)));
            Assert.AreEqual(1, pointOnCurve.NbPoints());
            Assert.AreEqual(0.0, pointOnCurve.Distance(1), MaxLengthDelta);
            Assert.AreEqual(pointOnCurve.Point(1).Distance(sketch.Points[p1]), pointOnCurve.Point(1).Distance(sketch.Points[p2]), MaxLengthDelta);
        }
Beispiel #2
0
        //--------------------------------------------------------------------------------------------------

        bool _CalcArcRimPoints(Pnt2d endPoint)
        {
            // Project end point on circle
            var startPoint = _Points[0];

            if ((startPoint.Distance(endPoint) <= 0) || (endPoint.Distance(_CenterPoint) <= 0) || (startPoint.Distance(_CenterPoint) <= 0))
            {
                return(false);
            }

            var xAxis        = new Ax2d(_CenterPoint, new Dir2d(new Vec2d(_CenterPoint, startPoint)));
            var radius       = _CenterPoint.Distance(startPoint);
            var circ         = new gp_Circ2d(xAxis, radius, _ArcDirection);
            var projEndPoint = new Geom2dAPI_ProjectPointOnCurve(endPoint, new Geom2d_Circle(circ)).NearestPoint();

            // Check if we should toggle the direction
            var endParameter = ElCLib.Parameter(circ, projEndPoint);

            // If the last parameter was very small (~PI/2), and the current is very high (~PI*1.5), toggle direction
            if (((_LastEndParameter < 1) && (endParameter > 5)) ||
                ((endParameter < 1) && (_LastEndParameter > 5)))
            {
                _ArcDirection = !_ArcDirection;
                circ          = new gp_Circ2d(xAxis, radius, _ArcDirection);
                endParameter  = ElCLib.Parameter(circ, projEndPoint);
            }
            _LastEndParameter = endParameter;

            // Calc rim point
            var rimPoint = ElCLib.Value(endParameter / 2, circ);

            _Points[1] = projEndPoint;
            _Points[2] = rimPoint;
            return(true);
        }
        public void PointOnSegmentCircle()
        {
            var sketch = Sketch.Create();
            var p1     = sketch.AddPoint(new Pnt2d(3, -10));
            var p2     = sketch.AddPoint(new Pnt2d(3, 10));
            var circle = new SketchSegmentCircle(p1, p2);
            var s1     = sketch.AddSegment(circle);
            var p3     = sketch.AddPoint(new Pnt2d(-5, -5));
            var p4     = sketch.AddPoint(new Pnt2d(20, 20));
            var s2     = sketch.AddSegment(new SketchSegmentLine(p3, p4));
            var c1     = sketch.AddConstraint(new SketchConstraintPointOnSegment(p3, s1));

            Assert.IsTrue(sketch.SolveConstraints(true));
            var pointOnCurve = new Geom2dAPI_ProjectPointOnCurve(sketch.Points[p3], circle.MakeCurve(sketch.Points));

            Assert.AreEqual(2, pointOnCurve.NbPoints());
            Assert.AreEqual(0.0, pointOnCurve.Distance(2), MaxLengthDelta);

            // Out of range
            sketch.Points[p3] = new Pnt2d(18, 18);
            Assert.IsTrue(sketch.SolveConstraints(true));
            pointOnCurve = new Geom2dAPI_ProjectPointOnCurve(sketch.Points[p3], circle.MakeCurve(sketch.Points));
            Assert.AreEqual(2, pointOnCurve.NbPoints());
            Assert.AreEqual(0.0, pointOnCurve.Distance(2), MaxLengthDelta);
        }
Beispiel #4
0
        //--------------------------------------------------------------------------------------------------

        void ProcessMouseInput(MouseEventData data)
        {
            SelectedSegment     = null;
            SelectedPointIndex  = -1;
            SelectedElementType = Sketch.ElementType.None;

            var element = _SketchEditorTool.Elements.FindOwner(data.DetectedAisInteractives.FirstOrDefault());

            if (element == null)
            {
                return;
            }

            if (element is SketchEditorSegmentElement segmentElement)
            {
                //
                // Segment
                //
                var segment = segmentElement.Segment;
                if (!SketchUtils.CanSplitSegment(_SketchEditorTool.Sketch, segment))
                {
                    return;
                }

                var curve = segment.CachedCurve ?? segment.MakeCurve(_SketchEditorTool.Sketch.Points);
                if (curve == null)
                {
                    return;
                }

                // Get new point from parameters
                double u = 0, v = 0;
                ElSLib.Parameters(_SketchEditorTool.Sketch.Plane, data.PointOnPlane, ref u, ref v);
                var sketchPoint  = new Pnt2d(u, v);
                var pointOnCurve = new Geom2dAPI_ProjectPointOnCurve(sketchPoint, curve);

                if (pointOnCurve.NbPoints() < 1)
                {
                    return;
                }

                SelectedParameter   = pointOnCurve.LowerDistanceParameter();
                SelectedSegment     = segment;
                _SelectedPoint      = _SketchEditorTool.Sketch.Plane.Value(curve.Value(SelectedParameter));
                SelectedElementType = Sketch.ElementType.Segment;
            }
            else if (element is SketchEditorPointElement pointElement)
            {
                //
                // Point
                //
                var pointIndex = pointElement.PointIndex;
                if (!SketchUtils.CanSplitPoint(_SketchEditorTool.Sketch, pointIndex))
                {
                    return;
                }

                SelectedPointIndex  = pointIndex;
                _SelectedPoint      = _SketchEditorTool.Sketch.Plane.Value(_SketchEditorTool.Sketch.Points[pointIndex]);
                SelectedElementType = Sketch.ElementType.Point;
            }
        }