public void EqualLines()
        {
            var sketch = Sketch.Create();
            var p1     = sketch.AddPoint(new Pnt2d(-10, -5));
            var p2     = sketch.AddPoint(new Pnt2d(0, 10));
            var line1  = new SketchSegmentLine(p1, p2);
            var s1     = sketch.AddSegment(line1);
            var p3     = sketch.AddPoint(new Pnt2d(-5, -5));
            var line2  = new SketchSegmentLine(p2, p3);
            var s2     = sketch.AddSegment(line2);
            var c1     = sketch.AddConstraint(new SketchConstraintEqual(s1, s2));

            Assert.IsTrue(sketch.SolveConstraints(true));
            Assert.AreEqual(line1.Length(sketch.Points), line2.Length(sketch.Points), MaxLengthDelta);
        }
Пример #2
0
        //--------------------------------------------------------------------------------------------------

        void _OnActionPreview(ToolAction toolAction)
        {
            if (toolAction == _PointAction)
            {
                if (_Segment != null)
                {
                    _Points[1] = _PointAction.Point;
                    _Element.OnPointsChanged(_Points, null);

                    _ValueHudElement?.SetValue(_Segment.Length(_Points));
                }

                _Coord2DHudElement?.SetValues(_PointAction.PointOnWorkingPlane.X, _PointAction.PointOnWorkingPlane.Y);
            }
        }
        //--------------------------------------------------------------------------------------------------

        void _OnActionPreview(ToolAction toolAction)
        {
            if (toolAction == _PointAction)
            {
                if (_Segment != null)
                {
                    _Points[1] = _PointAction.Point;
                    _Element.OnPointsChanged(_Points, null);

                    _LabelHudElement?.SetValue("Length: " + _Segment.Length(_Points).ToRoundedString() + " mm");
                }

                _Coord2DHudElement?.SetValues(_PointAction.Point.X, _PointAction.Point.Y);
            }
        }
Пример #4
0
        //--------------------------------------------------------------------------------------------------

        void _OnActionFinished(ToolAction toolAction)
        {
            if (toolAction == _PointAction)
            {
                if (_Segment == null)
                {
                    _Points.Add(0, _PointAction.Point);
                    _MergePointIndices[0] = _PointAction.MergeCandidateIndex;
                    _Points.Add(1, _PointAction.Point);
                    _Segment = new SketchSegmentLine(0, 1);

                    _Element            = new SketchEditorSegmentElement(_SketchEditorTool, -1, _Segment, _SketchEditorTool.Transform, _SketchEditorTool.Sketch.Plane);
                    _Element.IsCreating = true;
                    _Element.OnPointsChanged(_Points, null);

                    if (_ValueHudElement == null && _SketchEditorTool.WorkspaceController.HudManager != null)
                    {
                        _ValueHudElement               = _SketchEditorTool.WorkspaceController.HudManager?.CreateElement <ValueHudElement>(this);
                        _ValueHudElement.Label         = "Length:";
                        _ValueHudElement.Units         = ValueUnits.Length;
                        _ValueHudElement.ValueEntered += _ValueHudElement_ValueEntered;
                    }
                    _ValueHudElement?.SetValue(_Segment.Length(_Points));

                    _SketchEditorTool.StatusText = "Select end point for line.";

                    _PointAction.Reset();
                }
                else
                {
                    if (_Points[0].Distance(_PointAction.Point) < 0.001)
                    {
                        _PointAction.Reset();
                        return;
                    }

                    _Points[1]            = _PointAction.Point;
                    _MergePointIndices[1] = _PointAction.MergeCandidateIndex;

                    // Accept point
                    _PointAction.Stop();

                    _SketchEditorTool.FinishSegmentCreation(_Points, _MergePointIndices, new SketchSegment[] { _Segment }, null, _MergePointIndices[1] >= 0 ? -1 : 1);
                }
            }
        }