Esempio n. 1
0
        //--------------------------------------------------------------------------------------------------

        void _OnActionPreview(ToolAction toolAction)
        {
            if (toolAction == _PointAction)
            {
                switch (_PointsFinished)
                {
                case 1:
                    _HintLine.Set(_Points[0], _PointAction.Point, _SketchEditorTool.Sketch.Plane);
                    break;

                case 2:
                    _Points[1] = _PointAction.Point;
                    _Points[2] = _PointAction.Point;
                    _Element.OnPointsChanged(_Points, null);
                    break;

                case 3:
                    _Points[2] = _PointAction.Point;
                    _Element.OnPointsChanged(_Points, null);
                    break;
                }

                _Coord2DHudElement?.SetValues(_PointAction.Point.X, _PointAction.Point.Y);
            }
        }
Esempio n. 2
0
        //--------------------------------------------------------------------------------------------------

        void _OnActionPreview(ToolAction toolAction)
        {
            if (toolAction == _PointAction)
            {
                switch (_PointsCompleted)
                {
                case 1:
                    if (_HintLines[0] == null)
                    {
                        _HintLines[0] = new HintLine(_SketchEditorTool.WorkspaceController, HintStyle.ThinDashed | HintStyle.Topmost);
                    }
                    _HintLines[0].Set(_CenterPoint, _PointAction.Point, _SketchEditorTool.Sketch.Plane);
                    break;

                case 2:
                    if (_HintLines[1] == null)
                    {
                        _HintLines[1] = new HintLine(_SketchEditorTool.WorkspaceController, HintStyle.ThinDashed | HintStyle.Topmost);
                    }
                    _HintLines[1].Set(_CenterPoint, _PointAction.Point, _SketchEditorTool.Sketch.Plane);

                    if (_Segment != null)
                    {
                        _CalcArcRimPoints(_PointAction.Point);
                        _Element.OnPointsChanged(_Points, null);
                    }
                    break;
                }

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

        void _OnActionPreview(ToolAction toolAction)
        {
            if (toolAction == _PointAction)
            {
                switch (_PointsCompleted)
                {
                case 1:
                    var p1 = _Points[0];
                    var p2 = _PointAction.Point;
                    if (_PreviewLine == null)
                    {
                        _PreviewLine = new HintLine(_SketchEditorTool.WorkspaceController, HintStyle.ThinDashed | HintStyle.Topmost);
                    }
                    _PreviewLine.Set(p1, p2, _SketchEditorTool.Sketch.Plane);
                    break;

                case 2:
                    if (_Segment != null)
                    {
                        _Points[2] = _PointAction.Point;
                        _Element.OnPointsChanged(_Points, null);

                        if (_LabelHudElement == null)
                        {
                            _LabelHudElement = _SketchEditorTool.WorkspaceController.HudManager?.CreateElement <LabelHudElement>(this);
                        }
                        _LabelHudElement?.SetValue("Radius: " + _Segment.Radius(_Points).ToRoundedString());
                    }
                    break;
                }

                _Coord2DHudElement?.SetValues(_PointAction.Point.X, _PointAction.Point.Y);
            }
        }
Esempio n. 4
0
        //--------------------------------------------------------------------------------------------------

        void _OnActionPreview(ToolAction toolAction)
        {
            if (toolAction == _PointAction)
            {
                switch (_PointsCompleted)
                {
                case 1:
                    var p1 = _Points[0];
                    var p2 = _PointAction.Point;
                    _PreviewLine ??= new HintLine(_SketchEditorTool.WorkspaceController, HintStyle.ThinDashed | HintStyle.Topmost);
                    _PreviewLine.Set(p1, p2, _SketchEditorTool.Sketch.Plane);
                    break;

                case 2:
                    if (_Segment != null)
                    {
                        _Points[2] = _PointAction.Point;
                        _Element.OnPointsChanged(_Points, null);

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

                _Coord2DHudElement?.SetValues(_PointAction.PointOnWorkingPlane.X, _PointAction.PointOnWorkingPlane.Y);
            }
        }
Esempio n. 5
0
        //--------------------------------------------------------------------------------------------------

        void _SetEndPoint(Pnt2d point, int mergeCandidateIndex)
        {
            // End point
            if (_Points[0].Distance(point) < 0.001)
            {
                // Minimum length not met
                _PointAction.Reset();
                return;
            }

            _Points[1]            = point;
            _Points[2]            = point;
            _MergePointIndices[2] = mergeCandidateIndex;

            _Segment = new SketchSegmentBezier(0, 1, 2);

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

            _HintLine.Remove();
            _HintLine = null;

            _SketchEditorTool.WorkspaceController.HudManager?.RemoveElement(_ValueHudElement);
            _ValueHudElement = null;

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

            _PointAction.Reset();
            pointsFinished++;

            _SketchEditorTool.WorkspaceController.Invalidate();
            _SketchEditorTool.WorkspaceController.UpdateSelection();
        }
        //--------------------------------------------------------------------------------------------------

        internal void InitElements(Dictionary <int, Pnt2d> tempPoints)
        {
            var sketch = _SketchEditorTool.Sketch;
            var plane  = sketch.Plane;

            foreach (var segmentKvp in sketch.Segments)
            {
                var element = new SketchEditorSegmentElement(_SketchEditorTool, segmentKvp.Key, segmentKvp.Value, _SketchEditorTool.Transform, plane);
                element.OnPointsChanged(tempPoints, sketch.Segments, _MarkerCounts);
                SegmentElements.Add(element);
            }

            foreach (var constraint in sketch.Constraints)
            {
                var element = new SketchEditorConstraintElement(_SketchEditorTool, constraint, _SketchEditorTool.Transform, plane);
                element.OnPointsChanged(tempPoints, sketch.Segments, _MarkerCounts);
                ConstraintElements.Add(element);
            }

            foreach (var pointKvp in sketch.Points)
            {
                var element = new SketchEditorPointElement(_SketchEditorTool, pointKvp.Key, pointKvp.Value, _SketchEditorTool.Transform, plane);
                PointElements.Add(element);
            }

            _UpdateElementList();

            Elements.ForEach(c =>
            {
                c.Activate(true);
                c.UpdateVisual();
            });

            _SketchEditorTool.WorkspaceController.Invalidate();
        }
        //--------------------------------------------------------------------------------------------------

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

                    if (_LabelHudElement == null)
                    {
                        _LabelHudElement = _SketchEditorTool.WorkspaceController.HudManager?.CreateElement <LabelHudElement>(this);
                    }
                    if (_LabelHudElement != null)
                    {
                        _LabelHudElement.Text = "Radius: " + _Segment.Radius(_Points).ToRoundedString();
                    }
                }

                if (_Coord2DHudElement != null)
                {
                    _Coord2DHudElement.CoordinateX = _PointAction.Point.X;
                    _Coord2DHudElement.CoordinateY = _PointAction.Point.Y;
                }
            }
        }
Esempio n. 8
0
        //--------------------------------------------------------------------------------------------------

        void _OnActionFinished(ToolAction toolAction)
        {
            if (toolAction == _PointAction)
            {
                switch (_PointsCompleted)
                {
                case 0:
                    _Points.Add(0, _PointAction.Point);
                    _MergePointIndices[0] = _PointAction.MergeCandidateIndex;
                    _PointsCompleted++;

                    _SketchEditorTool.StatusText = "Select end point for circular arc.";

                    _PointAction.Reset();
                    break;

                case 1:
                    if (_Points[0].Distance(_PointAction.Point) < 0.001)
                    {
                        // Minimum length not met
                        _PointAction.Reset();
                        return;
                    }

                    _Points.Add(1, _PointAction.Point);
                    _MergePointIndices[1] = _PointAction.MergeCandidateIndex;
                    _PointsCompleted++;

                    _Points.Add(2, _PointAction.Point);
                    _Segment = new SketchSegmentArc(0, 1, 2);

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

                    _SketchEditorTool.StatusText = "Select rim point for circular arc.";

                    _PointAction.Reset();
                    break;

                case 2:
                    if (_Points[0].Distance(_PointAction.Point) < 0.001 ||
                        _Points[1].Distance(_PointAction.Point) < 0.001)
                    {
                        // Minimum length not met
                        _PointAction.Reset();
                        return;
                    }

                    _PointAction.Stop();

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

                    _SketchEditorTool.FinishSegmentCreation(_Points, _MergePointIndices, new SketchSegment[] { _Segment }, null);
                    break;
                }
            }
        }
Esempio n. 9
0
        //--------------------------------------------------------------------------------------------------

        void _OnActionFinished(ToolAction toolAction)
        {
            if (toolAction == _PointAction)
            {
                switch (_PointsCompleted)
                {
                case 0:
                    _CenterPoint = _PointAction.Point;
                    _Points.Add(0, _PointAction.Point);
                    _MergePointIndices[0] = _PointAction.MergeCandidateIndex;
                    _PointsCompleted++;

                    _SketchEditorTool.StatusText = "Select start point for elliptical arc.";

                    _PointAction.Reset();
                    break;

                case 1:
                    if (_CenterPoint.Distance(_PointAction.Point) < 0.001)
                    {
                        // Minimum distance not met
                        _PointAction.Reset();
                        return;
                    }

                    _StartPoint           = _PointAction.Point;
                    _StartPointMergeIndex = _PointAction.MergeCandidateIndex;
                    _PointsCompleted++;

                    _Points.Add(1, _PointAction.Point);
                    _Points.Add(2, _PointAction.Point);
                    _Segment = new SketchSegmentEllipticalArc(1, 2, 0);

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

                    _SketchEditorTool.StatusText = "Select end point for elliptical arc.";

                    _PointAction.Reset();
                    break;

                case 2:
                    if (!_CalcArcRimPoints(_PointAction.Point, _PointAction.MergeCandidateIndex))
                    {
                        // Minimum length not met
                        _PointAction.Reset();
                        return;
                    }

                    _PointAction.Stop();

                    _SketchEditorTool.FinishSegmentCreation(_Points, _MergePointIndices, new SketchSegment[] { _Segment }, null);
                    break;
                }
            }
        }
        //--------------------------------------------------------------------------------------------------

        void _OnActionPreview(ToolAction toolAction)
        {
            if (toolAction == _PointAction)
            {
                switch (_PointsCompleted)
                {
                case 1:
                    _PreviewLine ??= new HintCircle(_SketchEditorTool.WorkspaceController, HintStyle.ThinDashed | HintStyle.Topmost);
                    _HintLines[0] ??= new HintLine(_SketchEditorTool.WorkspaceController, HintStyle.ThinDashed | HintStyle.Topmost);
                    var circ = new gce_MakeCirc2d(_CenterPoint, _PointAction.Point).Value();
                    _PreviewLine.Set(circ, _SketchEditorTool.Sketch.Plane);
                    _HintLines[0].Set(_CenterPoint, _PointAction.Point, _SketchEditorTool.Sketch.Plane);

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

                case 2:
                    _HintLines[1] ??= new HintLine(_SketchEditorTool.WorkspaceController, HintStyle.ThinDashed | HintStyle.Topmost);
                    _HintLines[1].Set(_CenterPoint, _PointAction.Point, _SketchEditorTool.Sketch.Plane);

                    if (_ValueHudElement == null && _SketchEditorTool.WorkspaceController.HudManager != null)
                    {
                        _ValueHudElement               = _SketchEditorTool.WorkspaceController.HudManager?.CreateElement <ValueHudElement>(this);
                        _ValueHudElement.Label         = "Angle:";
                        _ValueHudElement.Units         = ValueUnits.Degree;
                        _ValueHudElement.ValueEntered += _ValueHudElement_AngleEntered;
                    }

                    if (_Segment != null)
                    {
                        if (_CalcArcRimPoints(_PointAction.Point))
                        {
                            _Element.OnPointsChanged(_Points, null);
                            _ValueHudElement?.SetValue(_Segment.Angle(_Points).ToDeg());
                        }
                        else
                        {
                            _Element.Remove();
                            _ValueHudElement?.SetValue(0);
                        }
                    }
                    break;
                }

                _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);
            }
        }
Esempio n. 12
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 (_HintLine != null)
                {
                    _HintLine.Set(_Points[0], _PointAction.Point, _SketchEditorTool.Sketch.Plane);
                }
                else if (_Segment != null)
                {
                    _Points[1] = _PointAction.Point;
                    _Element.OnPointsChanged(_Points, null);
                }

                _Coord2DHudElement?.SetValues(_PointAction.Point.X, _PointAction.Point.Y);
            }
        }
Esempio n. 14
0
        //--------------------------------------------------------------------------------------------------

        void _OnActionPreview(ToolAction toolAction)
        {
            if (toolAction == _PointAction)
            {
                switch (_PointsCompleted)
                {
                case 1:
                    if (_PreviewLine == null)
                    {
                        _PreviewLine = new HintCircle(_SketchEditorTool.WorkspaceController, HintStyle.ThinDashed | HintStyle.Topmost);
                    }
                    if (_HintLines[0] == null)
                    {
                        _HintLines[0] = new HintLine(_SketchEditorTool.WorkspaceController, HintStyle.ThinDashed | HintStyle.Topmost);
                    }
                    var p1   = _CenterPoint;
                    var p2   = _PointAction.Point;
                    var circ = new gce_MakeCirc2d(p1, p2).Value();
                    _PreviewLine.Set(circ, _SketchEditorTool.Sketch.Plane);
                    _HintLines[0].Set(_CenterPoint, _PointAction.Point, _SketchEditorTool.Sketch.Plane);

                    if (_LabelHudElement == null)
                    {
                        _LabelHudElement = _SketchEditorTool.WorkspaceController.HudManager?.CreateElement <LabelHudElement>(this);
                    }
                    _LabelHudElement?.SetValue("Radius: " + circ.Radius().ToRoundedString());
                    break;

                case 2:
                    if (_HintLines[1] == null)
                    {
                        _HintLines[1] = new HintLine(_SketchEditorTool.WorkspaceController, HintStyle.ThinDashed | HintStyle.Topmost);
                    }
                    _HintLines[1].Set(_CenterPoint, _PointAction.Point, _SketchEditorTool.Sketch.Plane);

                    if (_Segment != null)
                    {
                        _CalcArcRimPoints(_PointAction.Point);
                        _Element.OnPointsChanged(_Points, null);
                    }
                    break;
                }

                _Coord2DHudElement?.SetValues(_PointAction.Point.X, _PointAction.Point.Y);
            }
        }
Esempio n. 15
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);
                }
            }
        }
        //--------------------------------------------------------------------------------------------------

        void _SetStartPoint(Pnt2d point, int mergeCandidateIndex)
        {
            if (_CenterPoint.Distance(point) < 0.001)
            {
                // Minimum length not met
                _PointAction.Reset();
                return;
            }

            if (_PreviewLine != null)
            {
                _PreviewLine.Remove();
                _PreviewLine = null;
            }

            _HintLines[0].Set(_CenterPoint, point, _SketchEditorTool.Sketch.Plane);

            if (_ValueHudElement != null)
            {
                _SketchEditorTool.WorkspaceController.HudManager?.RemoveElement(_ValueHudElement);
                _ValueHudElement.ValueEntered -= _ValueHudElement_RadiusEntered;
                _ValueHudElement = null;
            }

            _Points.Add(0, point);
            _MergePointIndices[0] = mergeCandidateIndex;
            _PointsCompleted++;

            _Points.Add(1, point);
            _Points.Add(2, point);
            _Segment = new SketchSegmentArc(0, 1, 2);

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

            _SketchEditorTool.StatusText = "Select end point for circular arc.";

            _PointAction.Reset();
            _PointAction.ConstraintPoint += _PointActionOnConstraintPoint;

            _SketchEditorTool.WorkspaceController.Invalidate();
            _SketchEditorTool.WorkspaceController.UpdateSelection();
        }
        //--------------------------------------------------------------------------------------------------

        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 SketchSegmentCircle(0, 1);

                    _Marker = new Marker(_SketchEditorTool.WorkspaceController, Marker.Styles.Bitmap | Marker.Styles.Topmost, Marker.BallImage);
                    _Marker.Set(_PointAction.Point, _SketchEditorTool.Sketch.Plane);

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

                    _SketchEditorTool.WorkspaceController.Invalidate();

                    _SketchEditorTool.StatusText = "Select any rim point of the circle.";

                    _PointAction.Reset();
                }
                else
                {
                    if (_Points[0].Distance(_PointAction.Point) < 0.001)
                    {
                        // Minimum length not met
                        _PointAction.Reset();
                        return;
                    }

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

                    _PointAction.Stop();

                    _SketchEditorTool.FinishSegmentCreation(_Points, _MergePointIndices, new SketchSegment[] { _Segment }, null);
                }
            }
        }
Esempio n. 18
0
        //--------------------------------------------------------------------------------------------------

        void _OnActionPreview(ToolAction toolAction)
        {
            if (toolAction == _PointAction)
            {
                switch (pointsFinished)
                {
                case 1:
                    _Points[2] = _PointAction.Point;
                    _HintLine?.Set(_Points[0], _PointAction.Point, _SketchEditorTool.Sketch.Plane);
                    _ValueHudElement?.SetValue(_Points[0].Distance(_Points[2]));
                    break;

                case 2:
                    _Points[1] = _PointAction.Point;
                    _Element?.OnPointsChanged(_Points, null);
                    break;
                }

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

        void _SetFirstRimPoint(Pnt2d point, int mergeCandidateIndex)
        {
            if (_Points[0].Distance(point) < 0.001)
            {
                // Min distance not met
                _PointAction.Reset();
                return;
            }

            if (_HintCircle != null)
            {
                _HintCircle.Remove();
                _HintCircle = null;
            }

            if (_HintLine != null)
            {
                _HintLine.Remove();
                _HintLine = null;
            }

            _Points[1]            = point;
            _MergePointIndices[1] = mergeCandidateIndex;
            _PointsCompleted++;

            _Marker[1] = new Marker(_SketchEditorTool.WorkspaceController, Marker.Styles.Bitmap | Marker.Styles.Topmost, Marker.BallImage);
            _Marker[1].Set(point, _SketchEditorTool.Sketch.Plane);

            _Points[2] = point;
            _Segment   = new SketchSegmentEllipse(0, 1, 2);

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

            _SketchEditorTool.StatusText = "Select second rim point of the ellipse.";
            _PointAction.Reset();
            _SketchEditorTool.WorkspaceController.Invalidate();
            _SketchEditorTool.WorkspaceController.UpdateSelection();
        }
Esempio n. 20
0
        //--------------------------------------------------------------------------------------------------

        public bool Continue(int continueWithPoint)
        {
            // Start the next line with the first point already catched
            _Points[0]            = _SketchEditorTool.Sketch.Points[continueWithPoint];
            _MergePointIndices[0] = continueWithPoint;

            _Element?.Remove();

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

            _PointAction = new SketchPointAction(_SketchEditorTool);
            if (!_SketchEditorTool.WorkspaceController.StartToolAction(_PointAction, false))
            {
                return(false);
            }
            _PointAction.Previewed += _OnActionPreview;
            _PointAction.Finished  += _OnActionFinished;
            return(true);
        }
        //--------------------------------------------------------------------------------------------------

        internal void OnSketchChanged(Sketch sketch, Sketch.ElementType types)
        {
            if (sketch == _SketchEditorTool.Sketch)
            {
                if (types.HasFlag(Sketch.ElementType.Point))
                {
                    // Check for lost points
                    var lostPoints = PointElements.Where(pc => !sketch.Points.ContainsKey(pc.PointIndex)).ToArray();
                    foreach (var lostPoint in lostPoints)
                    {
                        lostPoint.Remove();
                        PointElements.Remove(lostPoint);
                    }
                }
                if (types.HasFlag(Sketch.ElementType.Segment))
                {
                    // Check for lost segments
                    var lostSegs = SegmentElements.Where(sc => !sketch.Segments.ContainsValue(sc.Segment)).ToArray();
                    foreach (var lostSeg in lostSegs)
                    {
                        lostSeg.Remove();
                        SegmentElements.Remove(lostSeg);
                    }
                }
                if (types.HasFlag(Sketch.ElementType.Constraint))
                {
                    // Check for lost constraints
                    var lostCons = ConstraintElements.Where(cc => !sketch.Constraints.Contains(cc.Constraint)).ToArray();
                    foreach (var lostCon in lostCons)
                    {
                        lostCon.Remove();
                        ConstraintElements.Remove(lostCon);
                    }
                }

                // Check for new ones
                if (types.HasFlag(Sketch.ElementType.Point))
                {
                    // Check for new points
                    var newPoints = sketch.Points.Where(kvp => !PointElements.Exists(pc => pc.PointIndex == kvp.Key));
                    foreach (var pointKvp in newPoints)
                    {
                        var element = new SketchEditorPointElement(_SketchEditorTool, pointKvp.Key, pointKvp.Value, _SketchEditorTool.Transform, sketch.Plane);
                        element.UpdateVisual();
                        element.Activate(true);
                        PointElements.Add(element);
                    }
                }
                if (types.HasFlag(Sketch.ElementType.Segment))
                {
                    // Check for new segments
                    var newSegs = sketch.Segments.Where(seg => !SegmentElements.Exists(sc => sc.Segment == seg.Value));
                    foreach (var segmentKvp in newSegs)
                    {
                        var element = new SketchEditorSegmentElement(_SketchEditorTool, segmentKvp.Key, segmentKvp.Value, _SketchEditorTool.Transform, sketch.Plane);
                        element.OnPointsChanged(sketch.Points, sketch.Segments, _MarkerCounts);
                        element.UpdateVisual();
                        element.Activate(true);
                        SegmentElements.Add(element);
                    }
                }
                if (types.HasFlag(Sketch.ElementType.Constraint))
                {
                    // Check for new constraints
                    var newCons = sketch.Constraints.Where(con => !ConstraintElements.Exists(cc => cc.Constraint == con));
                    foreach (var sketchConstraint in newCons)
                    {
                        var element = new SketchEditorConstraintElement(_SketchEditorTool, sketchConstraint, _SketchEditorTool.Transform, sketch.Plane);
                        element.OnPointsChanged(sketch.Points, sketch.Segments, _MarkerCounts);
                        element.UpdateVisual();
                        element.Activate(true);
                        ConstraintElements.Add(element);
                    }
                }

                // Update elements
                _UpdateElementList();

                if (types.HasFlag(Sketch.ElementType.Point))
                {
                    OnPointsChanged(sketch.Points, sketch.Segments);
                }

                _SketchEditorTool.WorkspaceController.Invalidate();
            }
        }
        //--------------------------------------------------------------------------------------------------

        void _OnActionFinished(ToolAction toolAction)
        {
            if (toolAction == _PointAction)
            {
                switch (pointsFinished)
                {
                case 0:
                    // Start point
                    _Points.Add(0, _PointAction.Point);
                    _MergePointIndices[0] = _PointAction.MergeCandidateIndex;

                    _HintLine = new HintLine(_SketchEditorTool.WorkspaceController, HintStyle.ThinDashed | HintStyle.Topmost);
                    _HintLine.Set(_PointAction.Point, _PointAction.Point, _SketchEditorTool.Sketch.Plane);

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

                    _PointAction.Reset();
                    pointsFinished++;
                    break;

                case 1:
                    // End point
                    if (_Points[0].Distance(_PointAction.Point) < 0.001)
                    {
                        // Minimum length not met
                        _PointAction.Reset();
                        return;
                    }

                    _Points.Add(1, _PointAction.Point);
                    _Points.Add(2, _PointAction.Point);
                    _MergePointIndices[2] = _PointAction.MergeCandidateIndex;

                    _Segment = new SketchSegmentBezier(0, 1, 2);

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

                    _HintLine.Remove();
                    _HintLine = null;

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

                    _PointAction.Reset();
                    pointsFinished++;
                    break;

                case 2:
                    // Control point, finished
                    _PointAction.Stop();

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

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

        void _OnActionFinished(ToolAction toolAction)
        {
            if (toolAction == _PointAction)
            {
                switch (_PointsCompleted)
                {
                case 0:
                    _Points.Add(0, _PointAction.Point);
                    _MergePointIndices[0] = _PointAction.MergeCandidateIndex;
                    _PointsCompleted++;

                    _Marker[0] = new Marker(_SketchEditorTool.WorkspaceController, Marker.Styles.Bitmap | Marker.Styles.Topmost, Marker.BallImage);
                    _Marker[0].Set(_PointAction.Point, _SketchEditorTool.Sketch.Plane);

                    _SketchEditorTool.StatusText = "Select first rim point of the ellipse.";

                    _PointAction.Reset();
                    break;

                case 1:
                    if (_Points[0].Distance(_PointAction.Point) < 0.001)
                    {
                        // Min distance not met
                        _PointAction.Reset();
                        return;
                    }

                    if (_HintCircle != null)
                    {
                        _HintCircle.Remove();
                        _HintCircle = null;
                    }
                    if (_HintLine != null)
                    {
                        _HintLine.Remove();
                        _HintLine = null;
                    }

                    _Points.Add(1, _PointAction.Point);
                    _MergePointIndices[1] = _PointAction.MergeCandidateIndex;
                    _PointsCompleted++;

                    _Marker[1] = new Marker(_SketchEditorTool.WorkspaceController, Marker.Styles.Bitmap | Marker.Styles.Topmost, Marker.BallImage);
                    _Marker[1].Set(_PointAction.Point, _SketchEditorTool.Sketch.Plane);

                    _Points.Add(2, _PointAction.Point);
                    _Segment = new SketchSegmentEllipse(0, 1, 2);

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

                    _SketchEditorTool.StatusText = "Select second rim point of the ellipse.";

                    _PointAction.Reset();
                    break;

                case 2:
                    if (_Points[0].Distance(_PointAction.Point) < 0.001 ||
                        _Points[1].Distance(_PointAction.Point) < 0.001)
                    {
                        // Min distance not met
                        _PointAction.Reset();
                        return;
                    }

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

                    _PointAction.Stop();

                    _SketchEditorTool.FinishSegmentCreation(_Points, _MergePointIndices, new SketchSegment[] { _Segment }, null);
                    break;
                }
            }
        }