Пример #1
0
        protected override Size ArrangeOverride(Size finalSize)
        {
            Point point = this.TransformToAncestor(this).Transform(new Point(0, 0));

            double desiredWidth  = AdornedElement.DesiredSize.Width;
            double desiredHeight = AdornedElement.DesiredSize.Height;

            double adornerWidth  = this.DesiredSize.Width;
            double adornerHeight = this.DesiredSize.Height;

            topLeft.Arrange(new Rect(-adornerWidth / 2, -adornerHeight / 2, adornerWidth, adornerHeight));
            topRight.Arrange(new Rect(desiredWidth - adornerWidth / 2, -adornerHeight / 2, adornerWidth, adornerHeight));
            bottomLeft.Arrange(new Rect(-adornerWidth / 2, desiredHeight - adornerHeight / 2, adornerWidth, adornerHeight));
            bottomRight.Arrange(new Rect(desiredWidth - adornerWidth / 2, desiredHeight - adornerHeight / 2, adornerWidth, adornerHeight));

            if (isExist == true)
            {
                isExist                    = false;
                dottedLine                 = new Rectangle();
                dottedLine.Stroke          = Brushes.SkyBlue;
                dottedLine.StrokeDashArray = DoubleCollection.Parse("3,10");
                dottedLine.Arrange(new Rect(point.X, point.Y, adornerWidth, adornerHeight));

                visualChildren.Add(dottedLine);
            }

            return(finalSize);
        }
Пример #2
0
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value == null)
            {
                return(null);
            }

            var mode = LicenseModes.License;

            if (Enum.TryParse(value.ToString(), out mode) && mode == LicenseModes.Disabled)
            {
                try
                {
                    return(DoubleCollection.Parse(parameter.ToString()));
                }
                catch (Exception)
                {
                    return(DoubleCollection.Parse("2"));
                }
            }
            else
            {
                return(null);
            }
        }
Пример #3
0
        private void AddLines()
        {
            Point pt1 = new Point();
            Point pt2 = new Point();

            pt1.X = Convert.ToDouble(tbX1.Text);
            pt1.Y = Convert.ToDouble(tbY1.Text);
            pt2.X = Convert.ToDouble(tbX2.Text);
            pt2.Y = Convert.ToDouble(tbY2.Text);
            double length =
                0.5 * Convert.ToDouble(tbLength.Text);

            line1                 = new Line();
            line1.X1              = pt1.X;
            line1.Y1              = pt1.Y;
            line1.X2              = pt2.X;
            line1.Y2              = pt2.Y;
            line1.Stroke          = Brushes.Gray;
            line1.StrokeThickness = 4;
            canvas1.Children.Add(line1);
            Canvas.SetLeft(tbPoint1, pt1.X);
            Canvas.SetTop(tbPoint1, pt1.Y);
            Canvas.SetLeft(tbPoint2, pt2.X);
            Canvas.SetTop(tbPoint2, pt2.Y);
            tbPoint1.Text = "Pt1(" + pt1.ToString() + ")";
            tbPoint2.Text = "Pt2(" + pt2.ToString() + ")";

            Vector v1  = pt1 - pt2;
            Matrix m1  = new Matrix();
            Point  pt3 = new Point();
            Point  pt4 = new Point();

            m1.Rotate(-90);
            v1.Normalize();
            v1                   *= length;
            line2                 = new Line();
            line2.Stroke          = Brushes.Gray;
            line2.StrokeThickness = 4;
            line2.StrokeDashArray =
                DoubleCollection.Parse("3, 1");
            pt3 = pt2 + v1 * m1;
            m1  = new Matrix();
            m1.Rotate(90);
            pt4      = pt2 + v1 * m1;
            line2.X1 = pt3.X;
            line2.Y1 = pt3.Y;
            line2.X2 = pt4.X;
            line2.Y2 = pt4.Y;
            canvas1.Children.Add(line2);
            Canvas.SetLeft(tbPoint3, pt3.X);
            Canvas.SetTop(tbPoint3, pt3.Y);
            Canvas.SetLeft(tbPoint4, pt4.X);
            Canvas.SetTop(tbPoint4, pt4.Y);
            pt3.X         = Math.Round(pt3.X, 0);
            pt3.Y         = Math.Round(pt3.Y, 0);
            pt4.X         = Math.Round(pt4.X, 0);
            pt4.Y         = Math.Round(pt4.Y, 0);
            tbPoint3.Text = "Pt3(" + pt3.ToString() + ")";
            tbPoint4.Text = "Pt4(" + pt4.ToString() + ")";
        }
Пример #4
0
 static void SetLineStyle(Shape shape, LineStyle lineStyle)
 {
     if (lineStyle == LineStyle.Dashed)
     {
         shape.StrokeDashArray = DoubleCollection.Parse("8,5");
         shape.StrokeDashCap   = PenLineCap.Round;
     }
 }
Пример #5
0
        /// <summary>
        /// Attempts to convert to a DoubleCollection from the given object.
        /// </summary>
        /// <returns>
        /// The DoubleCollection which was constructed.
        /// </returns>
        /// <exception cref="NotSupportedException">
        /// A NotSupportedException is thrown if the example object is null or is not a valid type
        /// which can be converted to a DoubleCollection.
        /// </exception>
        /// <param name="context"> The ITypeDescriptorContext for this call. </param>
        /// <param name="culture"> The requested CultureInfo.  Note that conversion uses "en-US" rather than this parameter. </param>
        /// <param name="value"> The object to convert to an instance of DoubleCollection. </param>
        public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
        {
            if (value is string source)
            {
                return(DoubleCollection.Parse(source));
            }

            throw GetConvertFromException(value);
        }
Пример #6
0
 /// <summary>
 /// Converts a string into a DoubleCollection.
 /// </summary>
 public override object ConvertFromString(string value, IValueSerializerContext context)
 {
     if (value != null)
     {
         return(DoubleCollection.Parse(value));
     }
     else
     {
         return(base.ConvertFromString(value, context));
     }
 }
Пример #7
0
        public override Shape GetDrawingObject()
        {
            return(new Line
            {
                Stroke = Brushes.BlueViolet,
                X1 = Point1.X,
                Y1 = Point1.Y,
                X2 = Point2.X,
                Y2 = Point2.Y,

                StrokeDashArray = DoubleCollection.Parse("6 6"),
                StrokeThickness = 2
            });
        }
Пример #8
0
        public Settings()
        {
            InitializeComponent();
            txtGameSizeSquare.Text = "";
            string Ticks = "1";
            Double tick  = 0.2;

            for (Double i = 1 + tick; i < 5;)
            {
                Ticks = string.Format("{0}, {1}", Ticks, i.ToString(System.Globalization.CultureInfo.InvariantCulture)); //So decimals will use dot!
                i    += tick;
            }
            slidGameSizeSquare.Ticks = DoubleCollection.Parse(Ticks);
            //MessageBox.Show(Ticks);
        }
Пример #9
0
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            try
            {
                var text = value as string;

                if (string.IsNullOrWhiteSpace(text))
                {
                    return new DoubleCollection {
                               1, 0
                    }
                }
                ;

                return(DoubleCollection.Parse(Regex.Replace(text, " {2,}", " ")));
            }
            catch (Exception)
            {
                return(new DoubleCollection {
                    1, 0
                });
            }
        }
Пример #10
0
        //마우스를 이동했을 때의 콜백
        private void Retangle_MouseMove(object sender, MouseEventArgs e)
        {
            //그룹으로 묶여있는 것이면 Mouse 동작 스킵
            if (IsGrouped)
            {
                return;
            }

            lock (m_MoveLock)
            {
                //마우스 캡쳐 상태일 때에만 일련 동작 진행
                if (m_IsCaptured)
                {
                    if (sender is FrameworkElement control && this.Parent is Canvas canvas)
                    {
                        e.Handled = true;

                        Vector sizeOffset = e.GetPosition(canvas) - m_LastSizePoint;
                        Vector deltaSize  = this.GetPointByRotation(new Point(sizeOffset.X, sizeOffset.Y), -m_Radian, new Point(RectRotateTransform.CenterX, RectRotateTransform.CenterY)) - new Point(-RectRotateTransform.CenterX, -RectRotateTransform.CenterY);
                        switch (control.Name)
                        {
                        //LEFT-TOP 빨간 사각형 클릭하여 그래픽 리사이징 하는 경우,
                        case "Size_NW":
                            RectRotateTransform = new RotateTransform(Rotation, this.Width > this.MinWidth ? m_RectWidth / 2 - deltaSize.X : this.MinWidth / 2 - m_RectWidth / 2, this.Height > this.MinHeight ? m_RectHeight / 2 - deltaSize.Y : this.MinHeight / 2 - m_RectHeight / 2);
                            if (m_RectWidth - deltaSize.X > this.MinWidth)
                            {
                                this.OriginX = m_RectOriginX + deltaSize.X;
                                this.Width   = m_RectWidth - deltaSize.X;
                            }
                            else
                            {
                                this.Width = this.MinWidth;
                            }
                            if (m_RectHeight - deltaSize.Y > this.MinHeight)
                            {
                                this.OriginY = m_RectOriginY + deltaSize.Y;
                                this.Height  = m_RectHeight - deltaSize.Y;
                            }
                            else
                            {
                                this.Height = this.MinHeight;
                            }
                            break;

                        //RIGHT-TOP 빨간 사각형 클릭하여 그래픽 리사이징 하는 경우,
                        case "Size_NE":
                            RectRotateTransform = new RotateTransform(Rotation, m_RectWidth / 2, this.Height > this.MinHeight ? m_RectHeight / 2 - deltaSize.Y : this.MinHeight / 2 - m_RectHeight / 2);
                            if (m_RectWidth + deltaSize.X > this.MinWidth)
                            {
                                this.Width = m_RectWidth + deltaSize.X;
                            }
                            else
                            {
                                this.Width = this.MinWidth;
                            }
                            if (m_RectHeight - deltaSize.Y > this.MinHeight)
                            {
                                this.OriginY = m_RectOriginY + deltaSize.Y;
                                this.Height  = m_RectHeight - deltaSize.Y;
                            }
                            else
                            {
                                this.Height = this.MinHeight;
                            }
                            break;

                        //LEFT-BOTTOM 빨간 사각형 클릭하여 그래픽 리사이징 하는 경우,
                        case "Size_SW":
                            RectRotateTransform = new RotateTransform(Rotation, this.Width > this.MinWidth ? m_RectWidth / 2 - deltaSize.X : this.MinWidth / 2 - m_RectWidth / 2, m_RectHeight / 2);
                            if (m_RectWidth - deltaSize.X > this.MinWidth)
                            {
                                this.OriginX = m_RectOriginX + deltaSize.X;
                                this.Width   = m_RectWidth - deltaSize.X;
                            }
                            else
                            {
                                this.Width = this.MinWidth;
                            }
                            if (m_RectHeight + deltaSize.Y > this.MinHeight)
                            {
                                this.Height = m_RectHeight + deltaSize.Y;
                            }
                            else
                            {
                                this.Height = this.MinHeight;
                            }
                            break;

                        //RIGHT-BOTTOM 빨간 사각형 클릭하여 그래픽 리사이징 하는 경우,
                        case "Size_SE":
                            RectRotateTransform = new RotateTransform(Rotation, m_RectWidth / 2, m_RectHeight / 2);
                            if (m_RectWidth + deltaSize.X > this.MinWidth)
                            {
                                this.Width = m_RectWidth + deltaSize.X;
                            }
                            else
                            {
                                this.Width = this.MinWidth;
                            }
                            if (m_RectHeight + deltaSize.Y > this.MinHeight)
                            {
                                this.Height = m_RectHeight + deltaSize.Y;
                            }
                            else
                            {
                                this.Height = this.MinHeight;
                            }
                            break;

                        //사각형 움직일 경우,
                        case "Movable_Grid":
                            if (m_LastMovePoint.X == 0 && m_LastMovePoint.Y == 0)
                            {
                                m_LastMovePoint = e.GetPosition(canvas);
                                break;
                            }
                            Vector moveOffset = e.GetPosition(canvas) - m_LastMovePoint;
                            this.OriginX   += moveOffset.X;
                            this.OriginY   += moveOffset.Y;
                            m_LastMovePoint = e.GetPosition(canvas);
                            break;

                        //사각형 회전시킬 경우,
                        case "Rotate_Grid":
                            if (m_RotationLine == null)
                            {
                                m_RotationLine = new Line
                                {
                                    X1              = m_RectOriginX + m_RectWidth / 2,
                                    Y1              = m_RectOriginY + m_RectHeight / 2,
                                    Stroke          = Brushes.Red,
                                    StrokeThickness = 2,
                                    StrokeDashArray = DoubleCollection.Parse("4,3")
                                };
                                canvas.Children.Add(m_RotationLine);
                            }
                            m_RotationLine.X2 = e.GetPosition(canvas).X;
                            m_RotationLine.Y2 = e.GetPosition(canvas).Y;
                            Radian            = Math.Atan2(e.GetPosition(canvas).Y - GetCenter().Y, e.GetPosition(canvas).X - GetCenter().X);
                            break;
                        }
                    }
                }
            }
        }
Пример #11
0
        public static UIElement[] GenerateGearCirclesGeometry(Point Center,
                                                              double DedendumDiameter, double BaseDiameter, double ReferencePitchDiameter,
                                                              double WorkingPitchDiameter, double AddendumDiameter)
        {
            List <UIElement> Elements = new();

            EllipseGeometry DedendumGeometry = new()
            {
                Center  = Center,
                RadiusX = DedendumDiameter / 2,
                RadiusY = DedendumDiameter / 2
            };

            EllipseGeometry BaseGeometry = new()
            {
                Center  = Center,
                RadiusX = BaseDiameter / 2,
                RadiusY = BaseDiameter / 2
            };

            EllipseGeometry RefPitchGeometry = new()
            {
                Center  = Center,
                RadiusX = ReferencePitchDiameter / 2,
                RadiusY = ReferencePitchDiameter / 2
            };

            EllipseGeometry WorkPitchGeometry = new()
            {
                Center  = Center,
                RadiusX = WorkingPitchDiameter / 2,
                RadiusY = WorkingPitchDiameter / 2
            };

            EllipseGeometry AddendumGeometry = new()
            {
                Center  = Center,
                RadiusX = AddendumDiameter / 2,
                RadiusY = AddendumDiameter / 2
            };

            Path DedendumPath = new()
            {
                Stroke          = Brushes.Black,
                StrokeThickness = 0.5,
                Data            = DedendumGeometry
            };

            Elements.Add(DedendumPath);

            Path BasePath = new()
            {
                Stroke          = Brushes.Black,
                StrokeThickness = 0.5,
                StrokeDashArray = DoubleCollection.Parse("1,1"),
                Data            = BaseGeometry
            };

            Elements.Add(BasePath);

            Path RefPitchPath = new()
            {
                Stroke          = Brushes.Black,
                StrokeThickness = 0.5,
                StrokeDashArray = DoubleCollection.Parse("3,1"),
                Data            = RefPitchGeometry
            };

            Elements.Add(RefPitchPath);

            Path WorkPitchPath = new()
            {
                Stroke          = Brushes.Black,
                StrokeThickness = 1,
                Data            = WorkPitchGeometry
            };

            Elements.Add(WorkPitchPath);

            Path AddendumPath = new()
            {
                Stroke          = Brushes.Black,
                StrokeThickness = 0.5,
                Data            = AddendumGeometry
            };

            Elements.Add(AddendumPath);

            return(Elements.ToArray());
        }

        public static SortedDictionary <double, CurveType> GenerateAngleData(
            double dTheta, double Teeth, double InvoluteAngle,
            double ToothSpacingAngle, double TipAngle, double StartAngleOffset)
        {
            SortedDictionary <double, CurveType> GearAngleData = new();
            const double InvoluteOffset = 0.0001;

            for (int j = 0; j < Teeth; j++)
            {
                GearAngleData.Add(StartAngleOffset + (j * ToothSpacingAngle) + InvoluteOffset, CurveType.RisingInvolute);
                GearAngleData.Add(InvoluteAngle + StartAngleOffset + (j * ToothSpacingAngle) - InvoluteOffset, CurveType.RisingInvolute);
            }

            double[] Tip = Generate.LinearSpaced(5, StartAngleOffset + InvoluteAngle, StartAngleOffset + InvoluteAngle + TipAngle);
            for (int j = 0; j < Teeth; j++)
            {
                foreach (double Item in Tip.Select(n => n + (j * ToothSpacingAngle)))
                {
                    GearAngleData.Add(Item, CurveType.Addendum);
                }
            }

            for (int j = 0; j < Teeth; j++)
            {
                GearAngleData.Add(StartAngleOffset + InvoluteAngle + TipAngle + (j * ToothSpacingAngle) + InvoluteOffset, CurveType.ReturningInvolute);
                GearAngleData.Add(StartAngleOffset + (2 * InvoluteAngle) + TipAngle + (j * ToothSpacingAngle) - InvoluteOffset, CurveType.ReturningInvolute);
            }

            double[] Dwell = Generate.LinearSpaced(5, StartAngleOffset + (2 * InvoluteAngle) + TipAngle, StartAngleOffset + ToothSpacingAngle);
            for (int j = 0; j < Teeth; j++)
            {
                foreach (double Item in Dwell.Select(n => n + (j * ToothSpacingAngle)))
                {
                    GearAngleData.Add(Item, CurveType.Dedendum);
                }
            }


            return(GearAngleData);
        }

        public static Point[] GenerateInvoluteProfile(double dTheta, double BaseRadius, double AddendumRadius,
                                                      double InvoluteAngle, bool IsDirectionInverted)
        {
            double Alpha           = InverseInvolute(InvoluteAngle);
            int    NegateDirection = IsDirectionInverted ? -1 : 1;

            List <Point> List = new();

            for (double i = 0; i < Alpha * 1.5; i += dTheta / 2)
            {
                Point InvolutePoint = new()
                {
                    X = BaseRadius * (Math.Cos(i) + (i * Math.Sin(i))),
                    Y = NegateDirection * BaseRadius * (Math.Sin(i) - (i * Math.Cos(i)))
                };

                if (Polar(InvolutePoint).Rho <= AddendumRadius)
                {
                    List.Add(InvolutePoint);
                }
            }
            return(List.ToArray());
        }

        public static PointCollection GenerateGearProfile(double dTheta,
                                                          double BaseRadius, double DedendumRadius, double AddendumRadius,
                                                          SortedDictionary <double, CurveType> AngleCollection, Point Center)
        {
            PointCollection Result = new();

            double?InvoluteMaxAngle = null;

            for (int i = 1; i < AngleCollection.Count; i++)
            {
                KeyValuePair <double, CurveType> Data = AngleCollection.ElementAt(i);
                double Theta = Data.Key;
                switch (Data.Value)
                {
                case CurveType.Dedendum:
                    Result.Add(TranslatePoint(new Point
                    {
                        X = DedendumRadius * Math.Cos(Theta),
                        Y = DedendumRadius * Math.Sin(Theta),
                    }, Center.X, Center.Y));
                    break;

                case CurveType.RisingInvolute:
                    if (AngleCollection.ElementAt(i - 1).Value != CurveType.RisingInvolute)
                    {
                        continue;
                    }

                    double  RisingInvAlpha = AngleCollection.ElementAt(i).Key - AngleCollection.ElementAt(i - 1).Key;
                    Point[] RisingInvolute = GenerateInvoluteProfile(dTheta, BaseRadius, AddendumRadius, RisingInvAlpha, false);

                    foreach (Point Item in RisingInvolute)
                    {
                        Point RaisingClampedPoint = Item;

                        if (DedendumRadius > BaseRadius)
                        {
                            PolarPoint RaisingPolarPoint = Polar(Item);
                            if (RaisingPolarPoint.Rho < DedendumRadius)
                            {
                                RaisingClampedPoint = Cartesian(DedendumRadius, RaisingPolarPoint.Theta);
                            }
                        }

                        Point RisingTranslatedPoint = TranslatePoint(RaisingClampedPoint, Center.X, Center.Y);
                        Point RisingRotatedPoint    = RotatePointAAroundB(RisingTranslatedPoint, Center,
                                                                          AngleCollection.ElementAt(i - 1).Key);

                        Result.Add(RisingRotatedPoint);
                    }
                    break;

                case CurveType.ReturningInvolute:
                    if (AngleCollection.ElementAt(i - 1).Value != CurveType.ReturningInvolute)
                    {
                        continue;
                    }

                    double  ReturningInvAlpha = AngleCollection.ElementAt(i).Key - AngleCollection.ElementAt(i - 1).Key;
                    Point[] ReturningInvolute = GenerateInvoluteProfile(dTheta, BaseRadius, AddendumRadius, ReturningInvAlpha, true);

                    foreach (Point Item in ReturningInvolute.Reverse())
                    {
                        Point ReturningClampedPoint = Item;

                        if (DedendumRadius > BaseRadius)
                        {
                            PolarPoint ReturningPolarPoint = Polar(Item);
                            if (ReturningPolarPoint.Rho < DedendumRadius)
                            {
                                ReturningClampedPoint = Cartesian(DedendumRadius, ReturningPolarPoint.Theta);
                            }
                        }

                        Point ReturningTranslatedPoint = TranslatePoint(ReturningClampedPoint, Center.X, Center.Y);
                        Point ReturningRotatedPoint    = RotatePointAAroundB(ReturningTranslatedPoint, Center,
                                                                             AngleCollection.ElementAt(i).Key);

                        Result.Add(ReturningRotatedPoint);
                    }
                    break;

                case CurveType.Addendum:
                    InvoluteMaxAngle ??= Theta - AngleCollection.ElementAt(i - 1).Key;

                    Result.Add(TranslatePoint(new Point
                    {
                        X = AddendumRadius * Math.Cos(Theta),
                        Y = AddendumRadius * Math.Sin(Theta),
                    }, Center.X, Center.Y));
                    break;
                }
            }
            return(Result);
        }

        public static CalculationsResultsData Calculate(double m, int z1, int z2, double x1, double x2)
        {
            double dTheta = 0.1;
            double alpha  = Radians(20);

            double i = (double)z2 / z1;

            double inv_alpha_prime = (2 * Math.Tan(alpha) * (x1 + x2) / (z1 + z2)) + Involute(alpha);
            double alpha_prime     = InverseInvolute(inv_alpha_prime);

            double y = (double)(z1 + z2) / 2 * ((Math.Cos(alpha) / Math.Cos(alpha_prime)) - 1);
            double a = (((double)(z1 + z2) / 2) + y) * m;

            // Pitch circle
            double d1 = z1 * m;
            double d2 = z2 * m;

            // Base circle
            double d_b1 = d1 * Math.Cos(alpha);
            double d_b2 = d2 * Math.Cos(alpha);

            // Working pitch diameter
            double d_prime1 = d_b1 / Math.Cos(alpha_prime);
            double d_prime2 = d_b2 / Math.Cos(alpha_prime);

            // Addendum
            double h_a1 = (1 + y - x1) * m;
            double h_a2 = (1 + y - x2) * m;
            //double h_a1 = (1 + x1) * m;
            //double h_a2 = (1 + x2) * m;

            // Addendum circle
            double d_a1 = d1 + (2 * h_a1);
            double d_a2 = d2 + (2 * h_a2);

            // Dedendum circle
            double h = (2.25 + y - (x1 + x2)) * m;
            //double h = 2.25 * m;
            double d_f1 = d_a1 - (2 * h);
            double d_f2 = d_a2 - (2 * h);

            // Overlap coefficient
            double epsilon = (Math.Sqrt(Math.Pow(d_a1 / 2, 2) - Math.Pow(d_b1 / 2, 2))
                              + Math.Sqrt(Math.Pow(d_a2 / 2, 2) - Math.Pow(d_b2 / 2, 2))
                              - (a * Math.Sin(alpha_prime))) / (Math.PI * m * Math.Cos(alpha));

            //Pitch
            double p1 = Math.PI * d1 / z1;
            double p2 = Math.PI * d2 / z2;
            double p  = Math.PI * m;
            //double spacing_1 = p / (d1 / 2);

            // Arc length of tooth at the reference pitch circle
            double s_1 = m * ((Math.PI / 2) + (2 * x1 * Math.Tan(alpha)));
            double s_2 = m * ((Math.PI / 2) + (2 * x2 * Math.Tan(alpha)));

            // Arc length of tooth at the working pitch circle
            double sw_1 = d_prime1 * ((s_1 / d1) - Involute(alpha_prime) + Involute(alpha));
            double sw_2 = d_prime2 * ((s_2 / d2) - Involute(alpha_prime) + Involute(alpha));

            // Arc length of tooth at the base pitch circle
            double sb_1 = d_b1 * ((sw_1 / d_prime1) + Involute(alpha_prime));
            double sb_2 = d_b2 * ((sw_2 / d_prime2) + Involute(alpha_prime));

            // InverseInvolute angle of whole involute curve
            double alpha_a1 = Math.Acos(d1 / d_a1 * Math.Cos(alpha));
            double alpha_a2 = Math.Acos(d2 / d_a2 * Math.Cos(alpha));

            // Arc length of tooth at the base pitch circle
            double sa_1 = d_a1 * ((sb_1 / d_b1) - Involute(alpha_a1));
            double sa_2 = d_a2 * ((sb_2 / d_b2) - Involute(alpha_a2));

            double tip_angle1 = 2 * sa_1 / d_a1;
            double tip_angle2 = 2 * sa_2 / d_a2;

            double ang  = 2 * s_1 / d1;
            double angw = 2 * sw_1 / d_prime1;
            double angb = 2 * sb_1 / d_b1;
            double anga = 2 * sa_1 / d_a1;

            double test  = Math.Acos(d1 / d1 * Math.Cos(alpha));
            double testw = Math.Acos(d1 / d_prime1 * Math.Cos(alpha));
            double testb = Math.Acos(d1 / d_b1 * Math.Cos(alpha));
            double testa = Math.Acos(d1 / d_a1 * Math.Cos(alpha));

            double rho = 0.38 * m;

            List <UIElement> GearElements = new();

            GearElements.AddRange(GenerateGearCirclesGeometry(new Point(0, 0), d_f1, d_b1, d1, d_prime1, d_a1));
            GearElements.AddRange(GenerateGearCirclesGeometry(new Point(a, 0), d_f2, d_b2, d2, d_prime2, d_a2));

            SortedDictionary <double, CurveType> Data1 = GenerateAngleData(dTheta, z1, Involute(alpha_a1), 2 * Math.PI / z1, tip_angle1, Involute(alpha_prime));
            PointCollection Points1       = GenerateGearProfile(dTheta, d_b1 / 2, d_f1 / 2, d_a1 / 2, Data1, new Point(0, 0));
            Polygon         InvoluteLine1 = new()
            {
                Stroke          = Brushes.DarkOrange,
                StrokeThickness = 0.75,
                Points          = Points1
            };

            GearElements.Add(InvoluteLine1);

            double Offset = ((double)1 / 2 * Math.PI) - (2 * sb_2 / d_b2) + Involute(alpha_prime);
            SortedDictionary <double, CurveType> Data2 = GenerateAngleData(dTheta, z2, Involute(alpha_a2), 2 * Math.PI / z2, tip_angle2, Offset);
            PointCollection Points2       = GenerateGearProfile(dTheta, d_b2 / 2, d_f2 / 2, d_a2 / 2, Data2, new Point(a, 0));
            Polygon         InvoluteLine2 = new()
            {
                Stroke          = Brushes.Red,
                StrokeThickness = 0.75,
                Points          = Points2
            };

            GearElements.Add(InvoluteLine2);

            GearCharacteristicsData Pinion = new()
            {
                NumberOfTeeth          = z1,
                ShiftCoefficient       = x1,
                ReferencePitchDiameter = d1,
                OperatingPitchDiameter = d_prime1,
                DedendumDiameter       = d_f1,
                AddendumDiameter       = d_a1,
                BaseCircleDiameter     = d_b1,
                ThicknessReference     = s_1,
                ThicknessOperating     = sw_1,
                ThicknessBase          = sb_1,
                ThicknessTip           = sa_1,
                AngleTip = alpha_a1
            };

            GearCharacteristicsData Gear = new()
            {
                NumberOfTeeth          = z2,
                ShiftCoefficient       = x2,
                ReferencePitchDiameter = d2,
                OperatingPitchDiameter = d_prime2,
                DedendumDiameter       = d_f2,
                AddendumDiameter       = d_a2,
                BaseCircleDiameter     = d_b2,
                ThicknessReference     = s_2,
                ThicknessOperating     = sw_2,
                ThicknessBase          = sb_2,
                ThicknessTip           = sa_2,
                AngleTip = alpha_a2
            };

            GearMechanismData MechanismData = new()
            {
                Module                    = m,
                PressureAngle             = 20,
                OperatingPressureAngle    = Degrees(alpha_prime),
                CenterDistance            = a,
                CenterDistanceCoefficient = y,
                TransmissionRatio         = i,
                ContactRatio              = epsilon,
                Pitch        = p,
                FilletRadius = rho
            };

            CalculationsResultsData Result = new()
            {
                GearData          = Gear,
                PinionData        = Pinion,
                MechanismData     = MechanismData,
                MechanismGeometry = GearElements,
                PinionPoints      = Points1,
                GearPoints        = Points2,
                ActionPosition    = new Point(Pinion.OperatingPitchDiameter / 2, 0),
                GearPosition      = new Point((Pinion.OperatingPitchDiameter / 2) + (Gear.OperatingPitchDiameter / 2), 0),
                PinionPosition    = new Point(0, 0)
            };

            return(Result);
        }
    }
}
Пример #12
0
        public Form1()
        {
            InitializeComponent();

            for (int i = 1; i < 25; ++i)
            {
                comboCOM.Items.Add("COM" + i);
            }
            comboCOM.SelectedItem = Settings.Default.COMPort;

            var strokeDashArray  = DoubleCollection.Parse("4,2");
            var strokeDashArray2 = DoubleCollection.Parse("2,2");


#if false
            //AddSeries(_viewModel.ModeValues, "Mode Normal vs. High", Colors.Blue, 2, Brushes.Transparent, null);
            AddSeries(_viewModel.SensorValues, "Vol. Avg", Color.FromArgb(0xff, 0xff, 0xA5, 0), 0.5, Brushes.Transparent, null);
            AddSeries(_viewModel.MaxSensorValues, "Vol. Max", Color.FromArgb(0xFF, 0xFF, 0x00, 0x00), 1.5, Brushes.Transparent, null);
            AddSeries(_viewModel.NoiseOffsetValues, "RMS Flt.", Colors.LightGreen, 1.5, Brushes.Transparent, strokeDashArray);
            AddSeries(_viewModel.rawSensorValues, "RMS", Colors.Green, 1.5, Brushes.Transparent, null);
            AddSeries(_viewModel.songAvgValues, "dB", Colors.Yellow, 1.5, Brushes.Transparent, null);
#else
            AddSeries(_viewModel.MaxSensorValues, "Max Sensor", Color.FromArgb(0xFF, 0xFF, 0x0, 0x00), 1.5, Brushes.Transparent, strokeDashArray);
            AddSeries(_viewModel.rawSensorValues, "Sensor raw", Color.FromArgb(0xff, 0xff, 0, 0), 1.0, Brushes.Transparent, strokeDashArray2);
            AddSeries(_viewModel.SensorValues, "Sensor", Color.FromArgb(0xff, 0xff, 0, 0), 1.0, new SolidColorBrush(Color.FromArgb(0x3f, 0xff, 0, 0)), null);
            AddSeries(_viewModel.NoiseOffsetValues, "Noice", Color.FromArgb(0xFF, 0xFF, 0x0, 0x00), 1.5, Brushes.Transparent, strokeDashArray);
            AddSeries(_viewModel.songAvgValues, "Song Avg Sensor", Colors.Yellow, 1.5, Brushes.Transparent, strokeDashArray);
            AddSeries(_viewModel.ModeValues, "Mode Normal vs. High", Colors.Blue, 2, Brushes.Transparent, null);
#endif

            cartesianChart1.DisableAnimations = true;
            cartesianChart1.Zoom = ZoomingOptions.Xy;
            //cartesianChart1.Pan= PanningOptions.X;

            //        var mapper = Mappers.Xy<Data>() //in this case value is of type <ObservablePoint>
            //.X(value => value.X) //use the X property as X
            //.Y(value => value.Y); //use the Y property as Y

#if false
            //the ChartValues property will store our values array
            ChartValues            = new ChartValues <MeasureModel>();
            cartesianChart1.Series = new SeriesCollection
            {
                new LineSeries
                {
                    Values            = ChartValues,
                    PointGeometrySize = 18,
                    StrokeThickness   = 4
                }
            };
            cartesianChart1.AxisX.Add(new Axis
            {
                DisableAnimations = true,
                LabelFormatter    = value => value.ToString(), // new DateTime((long)value).ToString("mm:ss"),
                Separator         = new LiveCharts.Wpf.Separator
                {
                    Step = 500 // ms
                }
            });

            cartesianChart1.AxisY.Add(new Axis
            {
                DisableAnimations = true,
                LabelFormatter    = value => value.ToString(), // new DateTime((long)value).ToString("mm:ss"),
                Separator         = new LiveCharts.Wpf.Separator
                {
                    Step = 50 // ms
                }
            });

            cartesianChart1.AxisY[0].MaxValue = 1050;
            cartesianChart1.AxisY[0].MinValue = 0;
#endif
            // ------------------------
        }
Пример #13
0
        private void Retangle_MouseMove(object sender, MouseEventArgs e)
        {
            if (m_IsCaptured)
            {
                lock (m_MoveLock)
                {
                    var control = sender as FrameworkElement;

                    Canvas canvas = this.Parent as Canvas;
                    if (control != null && this.Parent != null && canvas != null)
                    {
                        e.Handled = true;

                        Vector sizeOffset = e.GetPosition(canvas) - m_LastSizePoint;
                        Vector deltaSize  = this.GetPointByRotation(new Point(sizeOffset.X, sizeOffset.Y), -m_Radian, new Point(RectRotateTransform.CenterX, RectRotateTransform.CenterY)) - new Point(-RectRotateTransform.CenterX, -RectRotateTransform.CenterY);
                        switch (control.Name)
                        {
                        case "Size_NW":
                            RectRotateTransform = new RotateTransform(Rotation, this.Width > this.MinWidth ? m_RectWidth / 2 - deltaSize.X : this.MinWidth / 2 - m_RectWidth / 2, this.Height > this.MinHeight ? m_RectHeight / 2 - deltaSize.Y : this.MinHeight / 2 - m_RectHeight / 2);
                            if (m_RectWidth - deltaSize.X > this.MinWidth)
                            {
                                this.OriginX = m_RectOriginX + deltaSize.X;
                                this.Width   = m_RectWidth - deltaSize.X;
                            }
                            else
                            {
                                this.Width = this.MinWidth;
                            }
                            if (m_RectHeight - deltaSize.Y > this.MinHeight)
                            {
                                this.OriginY = m_RectOriginY + deltaSize.Y;
                                this.Height  = m_RectHeight - deltaSize.Y;
                            }
                            else
                            {
                                this.Height = this.MinHeight;
                            }
                            break;

                        case "Size_NE":
                            RectRotateTransform = new RotateTransform(Rotation, m_RectWidth / 2, this.Height > this.MinHeight ? m_RectHeight / 2 - deltaSize.Y : this.MinHeight / 2 - m_RectHeight / 2);
                            if (m_RectWidth + deltaSize.X > this.MinWidth)
                            {
                                this.Width = m_RectWidth + deltaSize.X;
                            }
                            else
                            {
                                this.Width = this.MinWidth;
                            }
                            if (m_RectHeight - deltaSize.Y > this.MinHeight)
                            {
                                this.OriginY = m_RectOriginY + deltaSize.Y;
                                this.Height  = m_RectHeight - deltaSize.Y;
                            }
                            else
                            {
                                this.Height = this.MinHeight;
                            }
                            break;

                        case "Size_SW":
                            RectRotateTransform = new RotateTransform(Rotation, this.Width > this.MinWidth ? m_RectWidth / 2 - deltaSize.X : this.MinWidth / 2 - m_RectWidth / 2, m_RectHeight / 2);
                            if (m_RectWidth - deltaSize.X > this.MinWidth)
                            {
                                this.OriginX = m_RectOriginX + deltaSize.X;
                                this.Width   = m_RectWidth - deltaSize.X;
                            }
                            else
                            {
                                this.Width = this.MinWidth;
                            }
                            if (m_RectHeight + deltaSize.Y > this.MinHeight)
                            {
                                this.Height = m_RectHeight + deltaSize.Y;
                            }
                            else
                            {
                                this.Height = this.MinHeight;
                            }
                            break;

                        case "Size_SE":
                            RectRotateTransform = new RotateTransform(Rotation, m_RectWidth / 2, m_RectHeight / 2);
                            if (m_RectWidth + deltaSize.X > this.MinWidth)
                            {
                                this.Width = m_RectWidth + deltaSize.X;
                            }
                            else
                            {
                                this.Width = this.MinWidth;
                            }
                            if (m_RectHeight + deltaSize.Y > this.MinHeight)
                            {
                                this.Height = m_RectHeight + deltaSize.Y;
                            }
                            else
                            {
                                this.Height = this.MinHeight;
                            }
                            break;

                        case "Movable_Grid":
                            if (m_LastMovePoint.X == 0 && m_LastMovePoint.Y == 0)
                            {
                                m_LastMovePoint = e.GetPosition(canvas);
                                break;
                            }
                            Vector moveOffset = e.GetPosition(canvas) - m_LastMovePoint;
                            this.OriginX   += moveOffset.X;
                            this.OriginY   += moveOffset.Y;
                            m_LastMovePoint = e.GetPosition(canvas);
                            break;

                        case "Rotate_Grid":
                            if (m_RotationLine == null)
                            {
                                m_RotationLine = new Line
                                {
                                    X1              = m_RectOriginX + m_RectWidth / 2,
                                    Y1              = m_RectOriginY + m_RectHeight / 2,
                                    Stroke          = Brushes.Red,
                                    StrokeThickness = 2,
                                    StrokeDashArray = DoubleCollection.Parse("4,3")
                                };
                                canvas.Children.Add(m_RotationLine);
                            }
                            m_RotationLine.X2 = e.GetPosition(canvas).X;
                            m_RotationLine.Y2 = e.GetPosition(canvas).Y;
                            Radian            = Math.Atan2(e.GetPosition(canvas).Y - GetCenter().Y, e.GetPosition(canvas).X - GetCenter().X);
                            break;
                        }
                    }
                }
            }
        }
Пример #14
0
        public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
        {
            string str = value as string;

            if (str != null)
            {
                str = str.Trim();
            }
            if (!string.IsNullOrEmpty(str))
            {
                string[] tokens = str.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
                double   scale  = 1.0;
                if (tokens.Length > 1) //it is a scaled font
                {
                    str   = tokens[0].Trim();
                    scale = double.Parse(tokens[1], CultureInfo.InvariantCulture);
                }

                if (char.IsLetter(str, 0)) //it is a predefined font
                {
                    if (scale == 1.0)      //use CurveStyleFont
                    {
                        return new IfcDraughtingPreDefinedCurveFont {
                                   Name = str
                        }
                    }
                    ;
                    else //CurveFontStyleAndScale
                    {
                        return new IfcCurveStyleFontAndScaling
                               {
                                   CurveFont = new IfcDraughtingPreDefinedCurveFont {
                                       Name = str
                                   },
                                   CurveFontScaling = scale
                               }
                    };
                }
                else //it should be CurveFontStyle or a CurveFontStyleAndScale
                {
                    DoubleCollection dc = DoubleCollection.Parse(str);
                    int rem;
                    int patterns = Math.DivRem(dc.Count, 2, out rem);
                    if (rem == 0 && patterns > 0) //we have an even number of stroke patterns
                    {
                        IfcCurveStyleFont font = new IfcCurveStyleFont();

                        for (int i = 0; i < dc.Count; i += 2)
                        {
                            font.PatternList.Add_Reversible(new IfcCurveStyleFontPattern
                            {
                                VisibleSegmentLength   = dc[i],
                                InvisibleSegmentLength = dc[i + 1]
                            });
                        }
                        if (scale == 1.0) //use CurveStyleFont
                        {
                            return(font);
                        }
                        else //CurveFontStyleAndScale
                        {
                            return new IfcCurveStyleFontAndScaling {
                                       CurveFont = font, CurveFontScaling = scale
                            }
                        };
                    }
                }
            }
            return(base.ConvertFrom(context, culture, value));
        }
Пример #15
0
        /// <summary>
        /// 构建地标
        /// </summary>
        public void Build()
        {
            if (!MatchUtils.IsEmpty(this.mark) && !MatchUtils.IsEmpty(this.mark.Target) && !MatchUtils.IsEmpty(this.mark.Target.Netmap) && this.mark.Target.Enable && this.mark.Enable)
            {
                // 地标光标
                this.Cursor = this.mark.Mouse;
                {
                    // 地标图片
                    this.MarkImage.Source = this.mark.Image;
                    // 地标标题
                    this.MarkLabel.ToolTip = this.mark.Title;
                    this.MarkImage.ToolTip = this.mark.Title;
                    this.TextFrame.ToolTip = this.mark.Title;
                    this.IconFrame.ToolTip = this.mark.Title;
                    // 地标文字
                    this.MarkLabel.Content = this.mark.Label;
                    // 地标透明
                    this.mark.Facade.Opacity = this.mark.Alpha / 100.0;
                    // 地标色彩
                    this.MarkLabel.Foreground = new SolidColorBrush(this.mark.Color);
                    this.MarkLabel.Background = new SolidColorBrush(this.mark.Scene);
                    // 地标字体
                    if (MatchUtils.IsEmpty(this.mark.Fonts))
                    {
                        this.MarkLabel.FontSize   = 12;
                        this.MarkLabel.FontStyle  = FontStyles.Normal;
                        this.MarkLabel.FontWeight = FontWeights.Normal;
                    }
                    else
                    {
                        this.MarkLabel.FontSize   = this.mark.Fonts.Size;
                        this.MarkLabel.FontStyle  = this.mark.Fonts.Ital ? FontStyles.Italic : FontStyles.Normal;
                        this.MarkLabel.FontWeight = this.mark.Fonts.Bold ? FontWeights.Bold : FontWeights.Normal;
                    }
                    // 地标尺寸
                    if (MatchUtils.IsEmpty(this.mark.Dimen))
                    {
                        this.MarkImage.Width  = 0;
                        this.MarkImage.Height = 0;
                    }
                    else
                    {
                        this.MarkImage.Width  = this.mark.Dimen.W;
                        this.MarkImage.Height = this.mark.Dimen.H;
                    }
                    // 地标边框
                    if (!MatchUtils.IsEmpty(this.mark.Frame))
                    {
                        switch (this.mark.Frame.Style)
                        {
                        case WMaper.Meta.Frame.Linear.DOT:
                        {
                            this.IconFrame.StrokeDashArray = (
                                this.TextFrame.StrokeDashArray = DoubleCollection.Parse("1,2")
                                );
                            break;
                        }

                        case WMaper.Meta.Frame.Linear.DASH:
                        {
                            this.IconFrame.StrokeDashArray = (
                                this.TextFrame.StrokeDashArray = DoubleCollection.Parse("2,2")
                                );
                            break;
                        }

                        case WMaper.Meta.Frame.Linear.DASHDOT:
                        {
                            this.IconFrame.StrokeDashArray = (
                                this.TextFrame.StrokeDashArray = DoubleCollection.Parse("2,2,1,2")
                                );
                            break;
                        }

                        default:
                        {
                            this.IconFrame.StrokeDashArray = (
                                this.TextFrame.StrokeDashArray = null
                                );
                            break;
                        }
                        }
                        this.MarkImage.Margin = (
                            this.MarkLabel.Padding = new Thickness(
                                this.IconFrame.StrokeThickness = (
                                    this.TextFrame.StrokeThickness = this.mark.Frame.Thick
                                    )
                                )
                            );
                        this.IconFrame.Stroke = (
                            this.TextFrame.Stroke = new SolidColorBrush(this.mark.Frame.Color)
                            );
                        // 合并边框
                        {
                            (this.MarkImage.Parent as Grid).Margin = new Thickness(
                                0, 0 - this.mark.Frame.Thick, 0, 0
                                );
                        }
                    }
                    else
                    {
                        // 取消边框
                        this.MarkLabel.Padding = new Thickness(1);
                        {
                            (this.MarkImage.Parent as Grid).Margin = (
                                this.MarkImage.Margin = new Thickness(
                                    this.IconFrame.StrokeThickness = (
                                        this.TextFrame.StrokeThickness = 0
                                        )
                                    )
                                );
                        }
                    }
                }
                // 强制绘制
                this.Adjust();
            }
        }