Beispiel #1
0
        //--------------------------------------------------------------------------------------------------

        public override bool OnMouseDown(MouseEventData data)
        {
            if (data.DetectedEntities.Count == 0)
            {
                double u = 0, v = 0;
                if (Gizmo.IsPartDetected(AIS_TranslationGizmo2D.Part.Part_Plane))
                {
                    _MoveConstraintX = false;
                    _MoveConstraintY = false;
                    _Moving          = true;
                }
                else if (Gizmo.IsPartDetected(AIS_TranslationGizmo2D.Part.Part_XAxis))
                {
                    _MoveConstraintX = false;
                    _MoveConstraintY = true;
                    _Moving          = true;
                }
                else if (Gizmo.IsPartDetected(AIS_TranslationGizmo2D.Part.Part_YAxis))
                {
                    _MoveConstraintX = true;
                    _MoveConstraintY = false;
                    _Moving          = true;
                }
                if (_Moving)
                {
                    ElSLib.Parameters(_Sketch.Plane, data.PointOnPlane, ref u, ref v);
                    _MoveStartPoint = new Pnt2d(u, v);
                    return(true);
                }
            }
            return(base.OnMouseDown(data));
        }
        //--------------------------------------------------------------------------------------------------

        public static Pnt2d Parameters(this Pln pln, Pnt pnt)
        {
            double u = 0, v = 0;

            ElSLib.Parameters(pln, pnt, ref u, ref v);
            return(new Pnt2d(u, v));
        }
Beispiel #3
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));
        }
        //--------------------------------------------------------------------------------------------------

        void ProcessMouseInput(MouseEventData data)
        {
            // Get new point from parameters
            double u = 0, v = 0;

            ElSLib.Parameters(_SketchEditorTool.Sketch.Plane, data.PointOnPlane, ref u, ref v);
            var sketchPoint = new Pnt2d(u, v);

            Point = Snap(sketchPoint);
        }
Beispiel #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);
            }
        }
Beispiel #6
0
        //--------------------------------------------------------------------------------------------------

        bool _CreateProjectedPointList(List <Pnt> vertexList)
        {
            _PointList = new List <Pnt2d>(_IndexList.Count);

            // Build plane
            var pnts = new TColgp_HArray1OfPnt(1, _IndexList.Count);

            for (int i = 0; i < _IndexList.Count; i++)
            {
                pnts.SetValue(i + 1, vertexList[_IndexList[i]]);
            }

            var buildPlane = new GeomPlate_BuildAveragePlane(pnts, pnts.Length(), 0, 1, 1);

            if (!buildPlane.IsPlane())
            {
                return(false);
            }

            Pln plane = buildPlane.Plane().Pln();
            //plane.Location = Pnt.Origin;

            // Project points on plane
            double u = 0, v = 0;

            foreach (var i in _IndexList)
            {
                ElSLib.Parameters(plane, vertexList[i], ref u, ref v);
                _PointList.Add(new Pnt2d(u, v));
            }

            // Get winding order of polygon
            double area = 0;

            for (int i = 0; i < _PointList.Count - 1; i++)
            {
                area += _PointList[i].X * _PointList[i + 1].Y - _PointList[i + 1].X * _PointList[i].Y;
            }
            if (area < 0)
            {
                _PointList.Reverse();
                _IndexList.Reverse();
            }

            return(true);
        }
Beispiel #7
0
        //--------------------------------------------------------------------------------------------------

        void ProcessMouseInput(MouseEventData data)
        {
            // Get new point from parameters
            double u = 0, v = 0;

            ElSLib.Parameters(_SketchEditorTool.Sketch.Plane, data.PointOnPlane, ref u, ref v);
            var sketchPoint = new Pnt2d(u, v);

            Point = Snap(sketchPoint);

            // Recalculate point on working plane
            if (_SketchEditorTool.Sketch.Plane.Location.IsEqual(WorkspaceController.Workspace.WorkingPlane.Location, 0.00001))
            {
                PointOnWorkingPlane = Point;
            }
            else
            {
                ElSLib.Parameters(WorkspaceController.Workspace.WorkingPlane, _SketchEditorTool.Sketch.Plane.Location, ref u, ref v);
                PointOnWorkingPlane = Point.Translated(new Vec2d(u, v));
            }
        }
        public static bool SnapToGrid(Pnt2d point, Sketch sketch, out Pnt2d snapPoint, out double distance)
        {
            var workspace = InteractiveContext.Current.WorkspaceController.Workspace;

            if (workspace.V3dViewer.Grid().IsActive())
            {
                double u = 0, v = 0;
                ElSLib.Parameters(sketch.Plane, workspace.WorkingPlane.Location, ref u, ref v);
                var wpOffset      = new XY(u, v);
                var coordOnWp     = point.ToXY() - wpOffset;
                var flipY         = new XY(1, -1);
                var snapCoordOnWp = workspace.ComputeGridPoint(coordOnWp * flipY) * flipY;
                snapPoint = (snapCoordOnWp + wpOffset).ToPnt();
                distance  = point.Distance(snapPoint);
                return(true);
            }

            snapPoint = new Pnt2d();
            distance  = 0;
            return(false);
        }
Beispiel #9
0
        //--------------------------------------------------------------------------------------------------

        void ProcessMouseInput(MouseEventData data)
        {
            SelectedSegment     = null;
            SelectedPointIndex  = -1;
            SelectedElementType = Sketch.ElementType.None;

            var element = _SketchEditorTool.Elements.FindOwner(data.DetectedAisInteractives.FirstOrDefault());

            if (element == null)
            {
                return;
            }

            if (element is SketchEditorSegmentElement segmentElement)
            {
                //
                // Segment
                //
                var segment = segmentElement.Segment;
                if (!SketchUtils.CanSplitSegment(_SketchEditorTool.Sketch, segment))
                {
                    return;
                }

                var curve = segment.CachedCurve ?? segment.MakeCurve(_SketchEditorTool.Sketch.Points);
                if (curve == null)
                {
                    return;
                }

                // Get new point from parameters
                double u = 0, v = 0;
                ElSLib.Parameters(_SketchEditorTool.Sketch.Plane, data.PointOnPlane, ref u, ref v);
                var sketchPoint  = new Pnt2d(u, v);
                var pointOnCurve = new Geom2dAPI_ProjectPointOnCurve(sketchPoint, curve);

                if (pointOnCurve.NbPoints() < 1)
                {
                    return;
                }

                SelectedParameter   = pointOnCurve.LowerDistanceParameter();
                SelectedSegment     = segment;
                _SelectedPoint      = _SketchEditorTool.Sketch.Plane.Value(curve.Value(SelectedParameter));
                SelectedElementType = Sketch.ElementType.Segment;
            }
            else if (element is SketchEditorPointElement pointElement)
            {
                //
                // Point
                //
                var pointIndex = pointElement.PointIndex;
                if (!SketchUtils.CanSplitPoint(_SketchEditorTool.Sketch, pointIndex))
                {
                    return;
                }

                SelectedPointIndex  = pointIndex;
                _SelectedPoint      = _SketchEditorTool.Sketch.Plane.Value(_SketchEditorTool.Sketch.Points[pointIndex]);
                SelectedElementType = Sketch.ElementType.Point;
            }
        }