示例#1
0
        //--------------------------------------------------------------------------------------------------

        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(_LabelHudElement);
            _LabelHudElement = null;
        }
        //--------------------------------------------------------------------------------------------------

        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;
        }
示例#3
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);
            }
        }
        //--------------------------------------------------------------------------------------------------

        void _ClearHints()
        {
            _HintCircle?.Remove();
            _HintCircle = null;

            if (_HintAngles != null)
            {
                foreach (var hintLine in _HintAngles)
                {
                    hintLine?.Remove();
                }

                _HintAngles = null;
            }


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

        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 _UpdateHints()
        {
            if (Entity?.Body?.Shape != Entity)
            {
                return;
            }

            var axis = Entity?.GetRotationAxis()?.Transformed(Entity.Body.GetTransformation());

            if (axis == null)
            {
                _ClearHints();
                return;
            }

            if (_HintCircle == null)
            {
                _HintCircle = new HintCircle(WorkspaceController, HintStyle.Solid);
            }

            _HintCircle.Set(new gp_Circ(axis.Value.ToAx2(), Entity.Radius));
            var(startAngle, endAngle) = Entity.GetStartEndAngles();
            _HintCircle.SetRange(startAngle, endAngle);

            if (_HintAngles == null)
            {
                _HintAngles    = new HintLine[3];
                _HintAngles[0] = new HintLine(WorkspaceController, HintStyle.ThinDashed);
                _HintAngles[1] = new HintLine(WorkspaceController, HintStyle.Solid);
                _HintAngles[2] = new HintLine(WorkspaceController, HintStyle.Dashed);
            }

            var centerPoint  = axis.Value.Location;
            var mainVec      = axis.Value.XDirection.ToVec() * Entity.Radius;
            var localRotAxis = new Ax1(Pnt.Origin, axis.Value.Axis.Direction);

            _HintAngles[0].Set(centerPoint, centerPoint.Translated(mainVec));
            _HintAngles[1].Set(centerPoint, centerPoint.Translated(mainVec.Rotated(localRotAxis, startAngle.ToRad())));
            _HintAngles[2].Set(centerPoint, centerPoint.Translated(mainVec.Rotated(localRotAxis, endAngle.ToRad())));

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

        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();
        }
示例#8
0
        //--------------------------------------------------------------------------------------------------

        void _OnActionFinished(ToolAction toolAction)
        {
            if (toolAction == _PointAction)
            {
                switch (_PointsCompleted)
                {
                case 0:
                    _CenterPoint = _PointAction.Point;
                    _PointsCompleted++;

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

                    _PointAction.Reset();
                    break;

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

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

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

                    _Points.Add(1, _PointAction.Point);
                    _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 end point for circular arc.";

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

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

                    _PointAction.Stop();

                    _MergePointIndices[1] = _PointAction.MergeCandidateIndex;
                    _MergePointIndices[2] = -1;

                    _SketchEditorTool.FinishSegmentCreation(_Points, _MergePointIndices, new SketchSegment[] { _Segment }, null);
                    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;
                }
            }
        }