/// <summary>
        /// Event handler for the <see cref="PickingTool.PreviewRequested"/> event.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="eventArgs">The <see cref="ToleratedObjectEventArgs"/> instance containing the event data.</param>
        private void OnPreviewRequested(object sender, ToleratedObjectEventArgs eventArgs)
        {
            this.Graphics.Clear();
            if (this.pickedPoints.Count < 1)
            {
                return;
            }

            var centroid      = this.pickedPoints.Last();
            var sectionLength = Distance.PointToPoint(eventArgs.HitPoint, centroid);

            var distances = new[] { this.heightValueBox.Value, this.widthValueBox.Value, this.radiusValueBox.Value, sectionLength };

            if (distances.Any(x => x < GeometryConstants.DISTANCE_EPSILON))
            {
                return;
            }

            var normal            = new Vector(eventArgs.HitPoint - centroid);
            var transitionSection = new TransitionSectionGeometry(
                this.heightValueBox.Value,
                this.widthValueBox.Value,
                sectionLength,
                this.radiusValueBox.Value,
                centroid,
                normal);

            this.DrawTransitionSection(transitionSection);
        }
예제 #2
0
        /// <summary>
        /// Gets a coordinate system aligned with the transition section.
        /// </summary>
        /// <param name="transitionSection">The section</param>
        /// <returns>The coordsys.</returns>
        public static CoordinateSystem GetSectionAlignedCoordsys(Component transitionSection)
        {
            var pointList = GetDefinitionPoints(transitionSection);

            if (pointList.Count >= 2)
            {
                return(TransitionSectionGeometry.GetBaseCoordsys(pointList[0], new Vector(pointList[1] - pointList[0])));
            }

            return(new CoordinateSystem());
        }
        /// <summary>
        /// Gets the rectangle, with the first segment being the right segment of the base, and going into counter
        /// clockwise direction.
        /// </summary>
        /// <returns>The list of segments.</returns>
        private List <LineSegment> GetRectangle()
        {
            var coordSys = DataFetcher.GetSectionAlignedCoordsys(this.Component);

            var height   = DataFetcher.GetBaseHeight(this.Component);
            var width    = DataFetcher.GetBaseWidth(this.Component);
            var radius   = DataFetcher.GetRadius(this.Component);
            var length   = DataFetcher.GetSectionLength(this.Component);
            var geometry = new TransitionSectionGeometry(height, width, length, radius, coordSys.Origin, coordSys.AxisX.Cross(coordSys.AxisY));

            return(geometry.RectangularSection.OfType <LineSegment>().ToList());
        }
        /// <summary>
        /// Draws a preview of the transition section that will be inserted.
        /// </summary>
        /// <param name="geometry">Geometry of the transition section.</param>
        private void DrawTransitionSection(TransitionSectionGeometry geometry)
        {
            this.DrawPolycurve(geometry.RectangularSection);
            this.DrawPolycurve(geometry.CircularSection);

            var conicalSections = geometry.RectangularSection
                                  .OfType <Arc>()
                                  .Zip(geometry.CircularSection.Select(c => c as Arc), (b, t) => new { Bottom = b, Top = t });

            foreach (var cone in conicalSections)
            {
                this.Graphics.DrawLine(cone.Bottom.StartPoint, cone.Top.StartPoint);
                this.Graphics.DrawLine(cone.Bottom.EndPoint, cone.Top.EndPoint);
            }
        }
        /// <summary>
        /// Draws the preview of the base of the transition section.
        /// </summary>
        /// <param name="width">Width of the base.</param>
        /// <param name="height">Height of the base.</param>
        private void DrawRectangle(double width, double height)
        {
            var coordSys = DataFetcher.GetSectionAlignedCoordsys(this.Component);

            var radius   = DataFetcher.GetRadius(this.Component);
            var length   = DataFetcher.GetSectionLength(this.Component);
            var geometry = new TransitionSectionGeometry(height, width, length, radius, coordSys.Origin, coordSys.AxisX.Cross(coordSys.AxisY));

            var rectangle = geometry.RectangularSection;

            foreach (var curve in rectangle)
            {
                if (curve is LineSegment segment)
                {
                    this.Graphics.DrawLine(segment.StartPoint, segment.EndPoint);
                }
                else if (curve is Arc arc)
                {
                    this.Graphics.DrawArc(arc);
                }
            }
        }