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);
        }
        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);
        }
Esempio n. 3
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;
            }
        }