Exemple #1
0
        //--------------------------------------------------------------------------------------------------

        protected bool ComputeCirclePoints(Dictionary <int, Pnt2d> points, SketchSegment segment, Pln plane, out Pnt center, out Pnt rim, out double radius)
        {
            center = Pnt.Origin;
            rim    = Pnt.Origin;

            Pnt2d?centerPoint2d = null;
            Pnt2d?rimPoint2d    = null;

            radius = 0;

            if (segment is SketchSegmentCircle)
            {
                var circleSegment = (SketchSegmentCircle)segment;
                centerPoint2d = points[circleSegment.CenterPoint];
                rimPoint2d    = points[circleSegment.RimPoint];
                radius        = circleSegment.Radius(points);
            }
            else if (segment is SketchSegmentArc)
            {
                var arcRimSegment = (SketchSegmentArc)segment;
                centerPoint2d = arcRimSegment.Center(points);
                rimPoint2d    = points[arcRimSegment.RimPoint];
                radius        = arcRimSegment.Radius(points);
            }

            if (centerPoint2d == null)
            {
                return(false);
            }

            center = ElSLib.Value(centerPoint2d.Value.X, centerPoint2d.Value.Y, plane);
            rim    = ElSLib.Value(rimPoint2d.Value.X, rimPoint2d.Value.Y, plane);

            return(true);
        }
        //--------------------------------------------------------------------------------------------------

        void ProcessMouseInput(MouseEventData data)
        {
            var snapInfo  = WorkspaceController.SnapHandler.Snap(data);
            var snapPoint = WorkspaceController.SnapHandler.SnapOnPlane(snapInfo);

            if (snapPoint != null)
            {
                // Point is snapped
                Point = ElSLib.Value(snapPoint.Value.X, snapPoint.Value.Y, WorkspaceController.Workspace.WorkingPlane);
                if (snapInfo.SnapMode != SnapMode.Grid)
                {
                    if (_HintLine == null)
                    {
                        _HintLine = new HintLine(WorkspaceController, HintStyle.ThinDashed);
                    }

                    _HintLine.Set(snapInfo.Point, Point);
                }
                else
                {
                    _HintLine?.Remove();
                }
            }
            else
            {
                Point = data.PointOnPlane;
                _HintLine?.Remove();
            }
        }
Exemple #3
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);
        }
Exemple #4
0
        //--------------------------------------------------------------------------------------------------

        public override bool OnMouseMove(MouseEventData data)
        {
            if (_Moving)
            {
                // Get new point from parameters
                double u = 0, v = 0;
                ElSLib.Parameters(_Sketch.Plane, data.PointOnPlane, ref u, ref v);
                var newPoint = new Pnt2d(u, v);

                // Calc delta
                MoveDelta = new Vec2d(newPoint.Coord.Subtracted(_MoveStartPoint.Coord));

                // Apply constraints
                ApplyConstraints();
                Snap();
                ApplyConstraints();

                // Calc new 3D center
                var newPos3D = ElSLib.Value(_Center2D.X + MoveDelta.X, _Center2D.Y + MoveDelta.Y, _Sketch.Plane);
                _GizmoPlane.SetLocation(newPos3D);
                Gizmo.SetComponent(_GizmoPlane);

                // Check for point merge candidates
                _MergePreviewMarkers.ForEach(m => m.Remove());
                _MergePreviewMarkers.Clear();
                foreach (var candidate in CheckMergePoints(MoveDelta))
                {
                    var point     = _Sketch.Points[candidate.Value];
                    var geomPoint = new Geom_CartesianPoint(point.X, point.Y, 0);
                    geomPoint.Transform(_Sketch.GetTransformation());
                    var marker = new Marker(WorkspaceController, Marker.Styles.Bitmap | Marker.Styles.Topmost, Marker.RingImage);
                    marker.Set(geomPoint);
                    marker.SetColor(Colors.Highlight);
                    _MergePreviewMarkers.Add(marker);
                }

                data.ForceReDetection = true;

                if (_Coord2DHudElement == null)
                {
                    _Coord2DHudElement = WorkspaceController.HudManager?.CreateElement <Coord2DHudElement>(this);
                    _Delta2DHudElement = WorkspaceController.HudManager?.CreateElement <Delta2DHudElement>(this);
                }
                if (_Coord2DHudElement != null)
                {
                    _Coord2DHudElement.CoordinateX = _Center2D.X + MoveDelta.X;
                    _Coord2DHudElement.CoordinateY = _Center2D.Y + MoveDelta.Y;
                }
                if (_Delta2DHudElement != null)
                {
                    _Delta2DHudElement.DeltaX = MoveDelta.X;
                    _Delta2DHudElement.DeltaY = MoveDelta.Y;
                }
            }

            return(base.OnMouseMove(data));
        }
Exemple #5
0
        //--------------------------------------------------------------------------------------------------

        void _UpdateTrihedron()
        {
            if (!Points.Any())
            {
                return;
            }

            // Calc Center
            var center = new XY();

            Points.ForEach(i => center.Add(_Sketch.Points[i].Coord));
            center.Divide(Points.Count);
            _Center2D = center.ToPnt();

            //Debug.WriteLine("MoveSketchPointAction - Center {0} {1}", center.X(), center.Y());

            // Project center point onto sketch plane
            var center3D = ElSLib.Value(center.X, center.Y, _Sketch.Plane);

            //Debug.WriteLine("MoveSketchPointAction - Center3D {0} {1} {2}", center3D.X(), center3D.Y(), center3D.Z());

            // Calculate center point on working plane
            if (_Sketch.Plane.Location.IsEqual(WorkspaceController.Workspace.WorkingPlane.Location, 0.00001))
            {
                _Center2DOnWorkingPlane = _Center2D;
            }
            else
            {
                double u = 0, v = 0;
                ElSLib.Parameters(WorkspaceController.Workspace.WorkingPlane, _Sketch.Plane.Location, ref u, ref v);
                _Center2DOnWorkingPlane = _Center2D.Translated(new Vec2d(u, v));
            }


            // Use plane from sketch, but translate it to center position
            var plane = _Sketch.Plane;

            plane.Location = center3D;
            _GizmoPlane    = new Geom_Plane(plane);
            _GeomPlane     = new Geom_Plane(plane);

            // Create Gizmo
            if (Gizmo == null)
            {
                Gizmo = new AIS_TranslationGizmo2D(_GizmoPlane);
                Gizmo.SetLength(100);
                WorkspaceController.Workspace.AisContext.Display(Gizmo, false);
            }
            else
            {
                Gizmo.SetComponent(_GeomPlane);
                WorkspaceController.Workspace.AisContext.Redisplay(Gizmo, false);
            }
        }
Exemple #6
0
        //--------------------------------------------------------------------------------------------------

        void _PreviewHeight(ToolAction toolAction)
        {
            if (!(toolAction is AxisValueAction axisValueAction))
            {
                return;
            }

            _ClearPreviews();

            _Position = ElSLib.Value(Math.Min(_PointPlane1.X, _PointPlane2.X), Math.Min(_PointPlane1.Y, _PointPlane2.Y), _Plane).Round();
            _Rotation = WorkspaceController.Workspace.GetWorkingPlaneRotation();
            if (_PreviewShape == null)
            {
                // Create solid
                _PreviewShape = new Box
                {
                    DimensionX = Math.Abs(_PointPlane1.X - _PointPlane2.X).Round(),
                    DimensionY = Math.Abs(_PointPlane1.Y - _PointPlane2.Y).Round(),
                    DimensionZ = 0.1
                };
            }

            var height = axisValueAction.Value.Round();

            _PreviewShape.DimensionZ = (Math.Abs(height) >= 0.001) ? height : 0.001;

            var ocShape = _PreviewShape.GetTransformedBRep();

            if (ocShape != null)
            {
                var trsf = new Trsf(_Rotation, _Position.ToVec());

                _AisPreviewEdges = new AIS_Shape(ocShape);
                _AisPreviewEdges.SetDisplayMode(0);
                _AisPreviewEdges.SetLocalTransformation(trsf);
                WorkspaceController.Workspace.AisContext.Display(_AisPreviewEdges, false);
                WorkspaceController.Workspace.AisContext.Deactivate(_AisPreviewEdges);

                _AisPreviewSolid = new AIS_Shape(ocShape);
                _AisPreviewSolid.SetDisplayMode(1);
                _AisPreviewSolid.SetLocalTransformation(trsf);
                WorkspaceController.Workspace.AisContext.Display(_AisPreviewSolid, false);
                WorkspaceController.Workspace.AisContext.Deactivate(_AisPreviewSolid);
            }

            StatusText = $"Selected height: {height:0.00}";
            if (_ValueHudElement != null)
            {
                _ValueHudElement.Value = height;
            }

            WorkspaceController.Invalidate();
        }
Exemple #7
0
        //--------------------------------------------------------------------------------------------------

        public override bool OnMouseMove(MouseEventData data)
        {
            if (!IsFinished)
            {
                EnsureMarker();

                ProcessMouseInput(data);

                _Marker.SetComponent(new Geom_CartesianPoint(ElSLib.Value(Point.X, Point.Y, _SketchEditorTool.Sketch.Plane)));
                WorkspaceController.Workspace.AisContext.RecomputePrsOnly(_Marker, false);
                WorkspaceController.Invalidate();

                UpdateMergeMarker();

                return(base.OnMouseMove(data));
            }
            return(false);
        }
        //--------------------------------------------------------------------------------------------------

        #endregion

        #region Screen Space Conversions

        public bool ScreenToPoint(int screenX, int screenY, out Pnt resultPnt)
        {
            try
            {
                var    viewPlane = GetViewPlane();
                double x = 0, y = 0, z = 0;
                V3dView.Convert(screenX, screenY, ref x, ref y, ref z);
                Pnt   convertedPoint        = new Pnt(x, y, z);
                Pnt2d convertedPointOnPlane = ProjLib.Project(viewPlane, convertedPoint);

                resultPnt = ElSLib.Value(convertedPointOnPlane.X, convertedPointOnPlane.Y, viewPlane);
                return(true);
            }
            catch (Exception)
            {
                Debug.Assert(false);
            }

            resultPnt = Pnt.Origin;
            return(false);
        }
        //--------------------------------------------------------------------------------------------------

        double?_ProcessMouseInputForAxis(MouseEventData data, out double distance)
        {
            var planeDir = WorkspaceController.ActiveViewport.GetRightDirection();

            planeDir.Cross(_Axis.Direction);
            //Console.WriteLine("PlaneDir: {0:0.00} | {1:0.00} | {2:0.00}", planeDir.X(), planeDir.Y(), planeDir.Z());
            var plane = new Pln(new Ax3(_Axis.Location, planeDir, _Axis.Direction));

            var snapInfo  = WorkspaceController.SnapHandler.Snap(data);
            var snapPoint = WorkspaceController.SnapHandler.SnapOnPlane(snapInfo, plane);

            if (snapPoint != null)
            {
                // Point snapped
                var extrema = new Extrema_ExtPC(ElSLib.Value(snapPoint.Value.X, snapPoint.Value.Y, plane), new GeomAdaptor_Curve(new Geom_Line(_Axis)), 1.0e-10);
                if (extrema.IsDone() && extrema.NbExt() >= 1)
                {
                    var value = extrema.Point(1).Parameter();
                    distance = snapInfo.Point.Distance(_Axis.Location);
                    return(value);
                }
            }
            else
            {
                Pnt convertedPoint;
                if (WorkspaceController.ActiveViewport.ScreenToPoint(plane, Convert.ToInt32(data.ScreenPoint.X), Convert.ToInt32(data.ScreenPoint.Y), out convertedPoint))
                {
                    var extrema = new Extrema_ExtPC(convertedPoint, new GeomAdaptor_Curve(new Geom_Line(_Axis)), 1.0e-10);
                    if (extrema.IsDone() && extrema.NbExt() >= 1)
                    {
                        var value = extrema.Point(1).Parameter();
                        distance = convertedPoint.Distance(_Axis.Location);
                        return(value);
                    }
                }
            }
            distance = 0;
            return(null);
        }
        //--------------------------------------------------------------------------------------------------

        public static Pnt Value(this Pln pln, Pnt2d uv)
        {
            return(ElSLib.Value(uv.X, uv.Y, pln));
        }