示例#1
0
        public void SplitPoint()
        {
            var sketch = TestSketchGenerator.CreateSketch(TestSketchGenerator.SketchType.Rectangle);

            Assert.IsTrue(SketchUtils.CanSplitPoint(sketch, 0));
            var newPoints = SketchUtils.SplitPoint(sketch, 0);

            Assert.That(newPoints.SequenceEqual(new[] { 4 }));
            Assert.AreEqual(5, sketch.Points.Count);

            Assert.AreEqual(4, sketch.Segments[0].StartPoint);
            Assert.AreEqual(0, sketch.Segments[3].EndPoint);
            Assert.IsFalse(SketchUtils.CanSplitPoint(sketch, 0));
        }
示例#2
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;
            }
        }