Example #1
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);
            }
        }
Example #2
0
        //--------------------------------------------------------------------------------------------------

        void _FinishBaseRect(ToolAction toolAction)
        {
            toolAction?.Stop();

            var axisPosition    = ElSLib.Value(_PointPlane2.X, _PointPlane2.Y, _Plane);
            var axisValueAction = new AxisValueAction(this, new Ax1(axisPosition, _Plane.Axis.Direction));

            axisValueAction.Previewed += _PreviewHeight;
            axisValueAction.Finished  += _FinishHeight;

            if (!WorkspaceController.StartToolAction(axisValueAction))
            {
                return;
            }

            WorkspaceController.HudManager?.RemoveElement(_Coord2DHudElement);
            _CurrentPhase = Phase.Height;
            StatusText    = "Select height.";

            WorkspaceController.HudManager?.RemoveElement(_MultiValueHudElement);
            _ValueHudElement = WorkspaceController.HudManager?.CreateElement <ValueHudElement>(this);
            if (_ValueHudElement != null)
            {
                _ValueHudElement.Label         = "Height:";
                _ValueHudElement.ValueEntered += _ValueEntered;
                _ValueHudElement.Units         = ValueUnits.Length;
            }

            WorkspaceController.HudManager?.SetCursor(Cursors.SetHeight);

            _PreviewHeight(axisValueAction);
        }
        //--------------------------------------------------------------------------------------------------

        void _FinishPivotPoint(ToolAction toolAction)
        {
            if (!(toolAction is PointAction pointAction))
            {
                return;
            }

            _Point = pointAction.Point.Round();
            pointAction.Stop();

            var axisValueAction = new AxisValueAction(this, new Ax1(_Point, Dir.DZ));

            if (!WorkspaceController.StartToolAction(axisValueAction))
            {
                return;
            }
            axisValueAction.Previewed += _PreviewRadius;
            axisValueAction.Finished  += _FinishRadius;

            _CurrentPhase = Phase.Radius;
            StatusText    = "Select Radius.";

            WorkspaceController.HudManager?.RemoveElement(_Coord2DHudElement);
            _ValueHudElement = WorkspaceController.HudManager?.CreateElement <ValueHudElement>(this);
            if (_ValueHudElement != null)
            {
                _ValueHudElement.Label         = "Radius:";
                _ValueHudElement.Units         = ValueUnits.Length;
                _ValueHudElement.ValueEntered += _ValueEntered;
            }

            WorkspaceController.HudManager?.SetCursor(Cursors.SetRadius);
        }
        //--------------------------------------------------------------------------------------------------

        public void Stop()
        {
            if (_HintCircle != null)
            {
                _HintCircle.Remove();
                _HintCircle = null;
            }
            if (_HintLine != null)
            {
                _HintLine.Remove();
                _HintLine = null;
            }
            for (int i = 0; i < _Marker.Length; i++)
            {
                if (_Marker[i] != null)
                {
                    _Marker[i].Remove();
                }
                _Marker[i] = null;
            }

            _Element?.Remove();
            _PointAction?.Stop();

            _SketchEditorTool.WorkspaceController.HudManager?.RemoveElement(_Coord2DHudElement);
            _Coord2DHudElement = null;
            _SketchEditorTool.WorkspaceController.HudManager?.RemoveElement(_ValueHudElement);
            _ValueHudElement = null;
        }
Example #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();
        }
        //--------------------------------------------------------------------------------------------------

        public void Stop()
        {
            if (_PreviewLine != null)
            {
                _PreviewLine.Remove();
                _PreviewLine = null;
            }
            for (int i = 0; i < _HintLines.Length; i++)
            {
                if (_HintLines[i] != null)
                {
                    _HintLines[i].Remove();
                }
                _HintLines[i] = null;
            }
            _Element?.Remove();

            _PointAction.ConstraintPoint -= _PointActionOnConstraintPoint;

            _PointAction.Stop();

            _SketchEditorTool.WorkspaceController.HudManager?.RemoveElement(_Coord2DHudElement);
            _Coord2DHudElement = null;
            _SketchEditorTool.WorkspaceController.HudManager?.RemoveElement(_ValueHudElement);
            _ValueHudElement = null;
        }
        //--------------------------------------------------------------------------------------------------

        void _FinishPivotPoint(ToolAction toolAction)
        {
            if (!(toolAction is PointAction pointAction))
            {
                return;
            }

            _Plane       = WorkspaceController.Workspace.WorkingPlane;
            _PointPlane1 = pointAction.PointOnPlane;
            _PivotPoint  = pointAction.Point;

            pointAction.Stop();
            pointAction = new PointAction(this);
            if (!WorkspaceController.StartToolAction(pointAction))
            {
                return;
            }
            pointAction.Previewed += _PreviewRadius;
            pointAction.Finished  += _FinishRadius;

            _CurrentPhase = Phase.Radius;
            StatusText    = "Select radius.";

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

            WorkspaceController.HudManager?.SetCursor(Cursors.SetRadius);
        }
        //--------------------------------------------------------------------------------------------------

        void _ValueHudElement_AngleEntered(ValueHudElement hudElement, double newValue)
        {
            if (newValue == 0)
            {
                return;
            }

            var startPoint = _Points[0];

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

            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 startParameter = ElCLib.Parameter(circ, startPoint);

            var endParameter = startParameter + newValue.ToRad();
            var endPoint     = ElCLib.Value(endParameter, circ);

            _ArcDirection = newValue < 0;

            if (!_CalcArcRimPoints(endPoint))
            {
                return;
            }

            _MergePointIndices[1] = -1;
            _MergePointIndices[2] = -1;
            _PointsCompleted++;

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

        void _ValueHudElement_ValueEntered(ValueHudElement hudelement, double newValue)
        {
            if (newValue <= 0)
            {
                return;
            }

            switch (_PointsCompleted)
            {
            case 1:
            {
                Vec2d vec = new(_Points[0], _Points[1]);
                if (vec.Magnitude() == 0)
                {
                    return;
                }

                _SetFirstRimPoint(_Points[0].Translated(vec.Normalized().Scaled(newValue)), -1);
            }
            break;

            case 2:
            {
                Vec2d vec = new(_Points[0], _Points[2]);
                if (vec.Magnitude() == 0)
                {
                    return;
                }

                _SetSecondRimPoint(_Points[0].Translated(vec.Normalized().Scaled(newValue)), -1);
            }
            break;
            }
        }
Example #10
0
        //--------------------------------------------------------------------------------------------------

        void _ValueEntered(ValueHudElement hudElement, double newValue)
        {
            if (_CurrentPhase == Phase.Height)
            {
                _PreviewShape.DimensionZ = (Math.Abs(newValue) >= 0.001) ? newValue : 0.001;
                _FinishHeight(null);
            }
        }
        //--------------------------------------------------------------------------------------------------

        void _ValueEntered(ValueHudElement hudElement, double newValue)
        {
            if (_CurrentPhase == Phase.Radius)
            {
                _PreviewShape.Radius = (Math.Abs(newValue) >= 0.001) ? newValue : 0.001;
                _FinishRadius(null);
            }
        }
Example #12
0
        //--------------------------------------------------------------------------------------------------

        public void Stop()
        {
            _Element?.Remove();
            _PointAction.Stop();
            _SketchEditorTool.WorkspaceController.HudManager?.RemoveElement(_Coord2DHudElement);
            _Coord2DHudElement = null;
            _SketchEditorTool.WorkspaceController.HudManager?.RemoveElement(_ValueHudElement);
            _ValueHudElement = null;
        }
        //--------------------------------------------------------------------------------------------------

        public override void Stop()
        {
            WorkspaceController.HudManager?.RemoveElement(_Coord2DHudElement);
            _Coord2DHudElement = null;
            WorkspaceController.HudManager?.RemoveElement(_ValueHudElement);
            _ValueHudElement = null;

            _ClearPreviews();
            base.Stop();
        }
        //--------------------------------------------------------------------------------------------------

        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 _ValueHudElement_RadiusEntered(ValueHudElement hudElement, double newValue)
        {
            if (newValue <= 0)
            {
                return;
            }

            Vec2d vec = new(_CenterPoint, _PointAction.Point);

            if (vec.Magnitude() == 0)
            {
                return;
            }

            _SetStartPoint(_CenterPoint.Translated(vec.Normalized().Scaled(newValue)), -1);
        }
Example #16
0
        //--------------------------------------------------------------------------------------------------

        void _ValueHudElement_ValueEntered(ValueHudElement hudElement, double newValue)
        {
            if (newValue <= 0)
            {
                return;
            }

            Vec2d vec = new(_Points[0], _Points[2]);

            if (vec.Magnitude() == 0)
            {
                return;
            }

            _SetEndPoint(_Points[0].Translated(vec.Normalized().Scaled(newValue)), -1);
        }
Example #17
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);
                }
            }
        }
Example #18
0
        //--------------------------------------------------------------------------------------------------

        void _OnActionFinished(ToolAction toolAction)
        {
            if (toolAction == _PointAction)
            {
                switch (pointsFinished)
                {
                case 0:
                    // Start point
                    _Points[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.";

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

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

                case 1:
                    _SetEndPoint(_PointAction.Point, _PointAction.MergeCandidateIndex);
                    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 _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();
        }
Example #20
0
        //--------------------------------------------------------------------------------------------------

        void _ValueHudElement_ValueEntered(ValueHudElement hudElement, double newValue)
        {
            if (newValue <= 0)
            {
                return;
            }

            Vec2d vec = new(_Points[0], _Points[1]);

            if (vec.Magnitude() == 0)
            {
                return;
            }

            _Points[1]            = _Points[0].Translated(vec.Normalized().Scaled(newValue));
            _MergePointIndices[1] = -1;
            _PointAction.Stop();
            _SketchEditorTool.FinishSegmentCreation(_Points, _MergePointIndices, new SketchSegment[] { _Segment }, null, 1);
        }
        //--------------------------------------------------------------------------------------------------

        void _ValueEntered(ValueHudElement hudElement, double newValue)
        {
            if (_CurrentPhase == Phase.Radius)
            {
                _Radius = (Math.Abs(newValue) >= 0.001) ? newValue : 0.001;
                _FinishRadius(null);
            }
            else if (_CurrentPhase == Phase.Height)
            {
                if (newValue > 0)
                {
                    _Position            = _PivotPoint.Round();
                    _PreviewShape.Height = newValue;
                }
                else
                {
                    _Position            = _PivotPoint.Translated(_Plane.Axis.Direction.ToVec().Multiplied(newValue)).Round();
                    _PreviewShape.Height = -newValue;
                }
                _FinishHeight(null);
            }
        }
Example #22
0
        //--------------------------------------------------------------------------------------------------

        void _ValueHudElement_RadiusEntered(ValueHudElement hudElement, double newValue)
        {
            if (newValue == 0)
            {
                return;
            }

            if (_Points[0].Distance(_Points[1]) == 0)
            {
                return;
            }

            var center       = Geom2dUtils.FindEllipseCenterFromEndpoints(_Points[0], _Points[1], newValue, newValue, 0, newValue > 0);
            var xAxis        = new Ax2d(center, new Dir2d(new Vec2d(center, _Points[0])));
            var radius       = center.Distance(_Points[0]);
            var circ         = new gp_Circ2d(xAxis, radius, newValue < 0);
            var endParameter = ElCLib.Parameter(circ, _Points[1]);

            _Points[2] = ElCLib.Value(endParameter / 2, circ);

            _MergePointIndices[2] = -1;
            _PointAction.Stop();
            _SketchEditorTool.FinishSegmentCreation(_Points, _MergePointIndices, new SketchSegment[] { _Segment }, null);
        }