コード例 #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);
        }
コード例 #2
0
        //--------------------------------------------------------------------------------------------------

        public int AddSegment(SketchSegment segment)
        {
            var index = Segments.Keys.Any() ? Segments.Keys.Max() + 1 : 0;

            Segments.Add(index, segment);
            return(index);
        }
コード例 #3
0
        //--------------------------------------------------------------------------------------------------

        public bool IsConnected(SketchSegment other)
        {
            var s1 = StartPoint;
            var s2 = other.StartPoint;
            var e1 = EndPoint;
            var e2 = other.EndPoint;

            return(((s1 != -1) && ((s1 == e2) || (s1 == s2))) ||
                   ((e1 != -1) && ((e1 == e2) || (e1 == s2))));
        }
コード例 #4
0
        //--------------------------------------------------------------------------------------------------

        public int AddSegment(SketchSegment segment)
        {
            SaveUndo(ElementType.Segment);
            var index = Segments.Keys.Any() ? Segments.Keys.Max() + 1 : 0;

            Segments.Add(index, segment);
            RaisePropertyChanged(nameof(Segments));
            OnElementsChanged(ElementType.Segment);
            return(index);
        }
コード例 #5
0
ファイル: SketchUtils.cs プロジェクト: Macad3D/Macad3D
        //--------------------------------------------------------------------------------------------------

        public static bool ReplaceSegmentPoint(SketchSegment segment, int oldPointIndex, int newPointIndex)
        {
            var segPoints = segment.Points;

            for (int itSegPoints = 0; itSegPoints < segPoints.Length; itSegPoints++)
            {
                if (segPoints[itSegPoints] != oldPointIndex)
                {
                    continue;
                }

                segPoints[itSegPoints] = newPointIndex;
                return(true);
            }

            return(false);
        }
コード例 #6
0
        //--------------------------------------------------------------------------------------------------

        public bool SetCircle(ref Circle circle, SketchSegment segment, List <Constraint> constraints, Dictionary <int, Pnt2d> points, bool isCenterConstant, bool isRadiusConstant)
        {
            var valid = true;

            if (segment is SketchSegmentCircle circSeg)
            {
                // Circle
                valid &= SetCircle(ref circle, circSeg.CenterPoint, circSeg.Radius(points), isCenterConstant, isRadiusConstant);

                var rimCon = new Constraint {
                    Type = ConstraintType.PointOnCircle
                };
                rimCon.Circle1 = circle;
                valid         &= SetPoint(ref rimCon.Point1, circSeg.RimPoint, false);
                constraints.Add(rimCon);
            }
            else if (segment is SketchSegmentArc arcSeg)
            {
                // Arc Rim
                int centerKey = 0;
                valid &= AddAuxiliaryPoint(out centerKey, arcSeg.Center(points), false);
                valid &= SetCircle(ref circle, centerKey, arcSeg.Radius(points), isCenterConstant, isRadiusConstant);

                for (int pointIndex = 0; pointIndex < 3; pointIndex++)
                {
                    var conPoint = new Constraint
                    {
                        Type    = ConstraintType.PointOnCircle,
                        Circle1 = circle
                    };
                    valid &= SetPoint(ref conPoint.Point1, arcSeg.Points[pointIndex], false);
                    constraints.Add(conPoint);
                }
            }
            else
            {
                valid = false;
            }
            return(valid);
        }
コード例 #7
0
ファイル: Sketch.cs プロジェクト: Macad3D/Macad3D
        //--------------------------------------------------------------------------------------------------

        public void DeleteSegment(SketchSegment segToDelete)
        {
            SaveUndo(ElementType.Point);
            SaveUndo(ElementType.Segment);
            int segIdToDelete = _Segments.First(kvp => kvp.Value == segToDelete).Key;

            // Look out for constraints who reference this segment
            bool changedConstraints = false;
            var  cons = Constraints.ToArray();

            foreach (var constraint in cons)
            {
                if (constraint.Segments == null)
                {
                    continue;
                }

                for (var i = 0; i < constraint.Segments.Length; i++)
                {
                    if (constraint.Segments[i] == segIdToDelete)
                    {
                        if (!changedConstraints)
                        {
                            SaveUndo(ElementType.Constraint);
                            changedConstraints = true;
                        }
                        _Constraints.Remove(constraint);
                    }
                }
            }

            // Remove segment
            _Segments.Remove(segIdToDelete);

            if (changedConstraints)
            {
                RaisePropertyChanged(nameof(Constraints));
            }
            RaisePropertyChanged(nameof(Segments));

            var deletedPoints = DeleteOrphanedPoints();

            // Look out for constraints who reference this segment
            foreach (var constraint in cons)
            {
                if (constraint.Points == null)
                {
                    continue;
                }

                for (var i = 0; i < constraint.Points.Length; i++)
                {
                    if (deletedPoints.Contains(constraint.Points[i]))
                    {
                        if (!changedConstraints)
                        {
                            SaveUndo(ElementType.Constraint);
                            changedConstraints = true;
                        }
                        _Constraints.Remove(constraint);
                    }
                }
            }

            ElementType types = ElementType.Segment | ElementType.Point;

            if (changedConstraints)
            {
                types |= ElementType.Constraint;
            }

            OnElementsChanged(types);

            Invalidate();
        }
コード例 #8
0
        //--------------------------------------------------------------------------------------------------

        protected SketchSegment Clone(SketchSegment targetSegment)
        {
            targetSegment.IsAuxilliary = IsAuxilliary;
            return(targetSegment);
        }