コード例 #1
0
        public void EditProp_Click(object sender, RoutedEventArgs e)
        {
            switch (selObject.Type)
            {
            case TargetObject.RLS:
            {
                RLSListWindow dlg = new RLSListWindow();
                dlg.rlsList = new List <RLS>(rlModel.RLSPositionList[selObject.Index].rlsList);
                foreach (RLS rls in dlg.rlsList)
                {
                    ListBoxItem lbi = new ListBoxItem();
                    dlg.RLSList_Set(ref lbi, rls);
                    dlg.rlsListBox.Items.Add(lbi);
                }
                dlg.ShowDialog();
                if (dlg.DialogResult == (bool?)true)
                {
                    // Удалить графически
                    foreach (RLS rls in rlModel.RLSPositionList[selObject.Index].rlsList)
                    {
                        modelCanvas.Children.Remove(rls.Pathes[GRID]);
                        modelCanvas.Children.Remove(rls.Pathes[VSR]);
                    }
                    if (dlg.rlsList.Count == 0)
                    {
                        // Если список пуст, то удалить и физически
                        rlModel.RLSPositionList.RemoveAt(selObject.Index);
                        UpdateRLSIndexes();
                    }
                    else         // Обновить графику для текущей позиции
                    {
                        rlModel.RLSPositionList[selObject.Index].rlsList = new List <RLS>(dlg.rlsList);
                        foreach (RLS rls in rlModel.RLSPositionList[selObject.Index].rlsList)
                        {
                            rls.RateAnimation = new DoubleAnimation(0.0, 360.0,
                                                                    TimeSpan.FromMinutes(1 / rls.Rate));
                            rls.RateAnimation.RepeatBehavior = RepeatBehavior.Forever;
                            string UID = SetUID();
                            this.RegisterName(UID, rls.RateTransform);
                            rlModel.playStrBoard.Children.Add(rls.RateAnimation);
                            RLSDraw(rlModel.RLSPositionList[selObject.Index].Position, rls);
                            Storyboard.SetTargetName(rls.RateAnimation, UID);
                            Storyboard.SetTargetProperty(rls.RateAnimation, new PropertyPath(RotateTransform.AngleProperty));
                            rls.Pathes[GRID].Tag = rlModel.RLSPositionList.IndexOf(rlModel.RLSPositionList[selObject.Index]);
                            rls.Pathes[VSR].Tag  = rlModel.RLSPositionList.IndexOf(rlModel.RLSPositionList[selObject.Index]);
                        }
                    }
                }
            }; break;

            case TargetObject.Path:
            {
            }; break;
            }
        }
コード例 #2
0
        public void modelCanvas_MouseLeftButtonDown(object sender, MouseEventArgs e)
        {
            Point mViewerPos = Mouse.GetPosition(modelScrollViewer);
            Point mCanvasPos = Mouse.GetPosition(modelCanvas);

            switch (editMode)
            {
            case (EditMode.Hand):
            {
                prvMousePosition = mViewerPos;
                crtMousePosition = prvMousePosition;
            } break;

            case (EditMode.RLS):
            {
                if (trgObject == TargetObject.None)
                {
                    RLSListWindow dlg = new RLSListWindow();
                    dlg.rlsList = new List <RLS> {
                    };
                    dlg.ShowDialog();
                    if (dlg.DialogResult == (bool?)true)
                    {
                        RLSPosition rlsPos = new RLSPosition(mCanvasPos);
                        rlModel.RLSPositionList.Add(rlsPos);
                        foreach (RLS rls in dlg.rlsList)
                        {
                            rls.RateAnimation = new DoubleAnimation(0.0, 360.0,
                                                                    TimeSpan.FromMinutes(1 / rls.Rate));
                            rls.RateAnimation.RepeatBehavior = RepeatBehavior.Forever;
                            string UID = SetUID();
                            this.RegisterName(UID, rls.RateTransform);
                            rlModel.playStrBoard.Children.Add(rls.RateAnimation);
                            RLSDraw(rlsPos.Position, rls);
                            Storyboard.SetTargetName(rls.RateAnimation, UID);
                            Storyboard.SetTargetProperty(rls.RateAnimation, new PropertyPath(RotateTransform.AngleProperty));
                            rlsPos.rlsList.Add(rls);
                            rls.Pathes[GRID].Tag = rlModel.RLSPositionList.IndexOf(rlsPos);
                            rls.Pathes[VSR].Tag  = rlModel.RLSPositionList.IndexOf(rlsPos);
                        }
                    }
                }
                else if (trgObject == TargetObject.RLS)
                {
                    prvMousePosition = mCanvasPos;
                    crtMousePosition = prvMousePosition;
                    //MessageBox.Show("РЛС. Индекс = " + trgIndex.ToString() + Environment.NewLine +
                    //                "Выделана РЛС = " + selTrgIndex);
                }
            } break;

            case (EditMode.Path):
            {
                if (trgObject == TargetObject.None)
                {
                    newTracePolyLine                 = new Polyline();
                    newTracePolyLine.Stroke          = Brushes.Blue;
                    newTracePolyLine.StrokeThickness = 5.0;
                    newTracePolyLine.StrokeDashArray.Add(10.0);
                    newTracePolyLine.StrokeDashArray.Add(5.0);
                    newTracePolyLine.Points.Add(mCanvasPos);
                    newTracePolyLine.Points.Add(mCanvasPos);
                    modelCanvas.Children.Add(newTracePolyLine);
                    editMode = EditMode.PathDraw;
                }
            } break;

            case (EditMode.PathDraw):
            {
                if ((newTracePolyLine.Points.Count > 1) &&
                    (newTracePolyLine.Points[newTracePolyLine.Points.Count - 2] == mCanvasPos))
                {
                    double traceLength = 0.0;
                    for (int i = 1; i < newTracePolyLine.Points.Count; i++)
                    {
                        traceLength += Math.Sqrt(Math.Pow((newTracePolyLine.Points[i].Y - newTracePolyLine.Points[i - 1].Y), 2) +
                                                 Math.Pow((newTracePolyLine.Points[i].X - newTracePolyLine.Points[i - 1].X), 2));
                    }
                    traceLength /= RLModel.PX2KM;         // graphic to real length
                    TraceOptionsWindow dlg = new TraceOptionsWindow();
                    dlg.lenghtTextBox.Text = traceLength.ToString("F");
                    dlg.ShowDialog();
                    if (dlg.DialogResult == (bool?)true)
                    {
                        FOTrace newFOTrace = new FOTrace();
                        newFOTrace.Length   = traceLength;
                        newFOTrace.Speed    = dlg.speedSlider.Value;
                        newFOTrace.IndvNumb = UInt32.Parse(dlg.indvNumbTextBox.Text);
                        newFOTrace.BgnOT    = double.Parse(dlg.bgnOTTextBox.Text);
                        newFOTrace.EndOT    = double.Parse(dlg.endOTTextBox.Text);
                        newFOTrace.BgnH     = double.Parse(dlg.bgnHTextBox.Text);
                        newFOTrace.EndH     = double.Parse(dlg.endHTextBox.Text);
                        newFOTrace.Trouble  = dlg.troubleCheckBox.IsChecked.Value;

                        for (int i = 0; i < newTracePolyLine.Points.Count; i++)
                        {
                            newFOTrace.PntList.Add(new Point(newTracePolyLine.Points[i].X / RLModel.PX2KM,
                                                             newTracePolyLine.Points[i].Y / RLModel.PX2KM));
                        }
                        double a = -Math.Atan((newTracePolyLine.Points[1].X - newTracePolyLine.Points[0].X) /
                                              (newTracePolyLine.Points[1].Y - newTracePolyLine.Points[0].Y)) * 180 / Math.PI;
                        if (newTracePolyLine.Points[1].Y - newTracePolyLine.Points[0].Y >= 0)
                        {
                            a += 180;
                        }
                        newFOTrace.FORotateTransform = new RotateTransform(a - 90.0, 0.0, 0.0);
                        newFOTrace.FOTransTransform  = new TranslateTransform(newTracePolyLine.Points[0].X,
                                                                              newTracePolyLine.Points[0].Y);

                        #region SetPlayAnimation
                        newFOTrace.FOXAnim = new DoubleAnimationUsingPath();
                        newFOTrace.FOXAnim.RepeatBehavior = new RepeatBehavior(1);
                        if (newFOTrace.Speed != 0.0)
                        {
                            newFOTrace.FOXAnim.Duration = new Duration(TimeSpan.FromHours(newFOTrace.Length / newFOTrace.Speed));
                        }
                        else
                        {
                            newFOTrace.FOXAnim.Duration = Duration.Forever;
                        }
                        string UID = SetUID();
                        this.RegisterName(UID, newFOTrace.FOTransTransform);
                        Storyboard.SetTargetName(newFOTrace.FOXAnim, UID);
                        Storyboard.SetTargetProperty(newFOTrace.FOXAnim, new PropertyPath(TranslateTransform.XProperty));
                        newFOTrace.FOXAnim.Source = PathAnimationSource.X;

                        newFOTrace.FOYAnim = new DoubleAnimationUsingPath();
                        newFOTrace.FOYAnim.RepeatBehavior = new RepeatBehavior(1);
                        if (newFOTrace.Speed != 0.0)
                        {
                            newFOTrace.FOYAnim.Duration = new Duration(TimeSpan.FromHours(newFOTrace.Length / newFOTrace.Speed));
                        }
                        else
                        {
                            newFOTrace.FOYAnim.Duration = Duration.Forever;
                        }
                        UID = SetUID();
                        this.RegisterName(UID, newFOTrace.FOTransTransform);
                        Storyboard.SetTargetName(newFOTrace.FOYAnim, UID);
                        Storyboard.SetTargetProperty(newFOTrace.FOYAnim, new PropertyPath(TranslateTransform.YProperty));
                        newFOTrace.FOYAnim.Source = PathAnimationSource.Y;

                        newFOTrace.FOAAnim = new DoubleAnimationUsingPath();
                        newFOTrace.FOAAnim.RepeatBehavior = new RepeatBehavior(1);
                        if (newFOTrace.Speed != 0.0)
                        {
                            newFOTrace.FOAAnim.Duration = new Duration(TimeSpan.FromHours(newFOTrace.Length / newFOTrace.Speed));
                        }
                        else
                        {
                            newFOTrace.FOAAnim.Duration = Duration.Forever;
                        }
                        UID = SetUID();
                        this.RegisterName(UID, newFOTrace.FORotateTransform);
                        Storyboard.SetTargetName(newFOTrace.FOAAnim, UID);
                        Storyboard.SetTargetProperty(newFOTrace.FOAAnim, new PropertyPath(RotateTransform.AngleProperty));
                        newFOTrace.FOAAnim.Source = PathAnimationSource.Angle;
                        #endregion SetPlayAnimation

                        TraceDraw(newFOTrace);

                        rlModel.playStrBoard.Children.Add(newFOTrace.FOXAnim);
                        rlModel.playStrBoard.Children.Add(newFOTrace.FOYAnim);
                        rlModel.playStrBoard.Children.Add(newFOTrace.FOAAnim);

                        rlModel.FOTraceList.Add(newFOTrace);
                    }
                    newTracePolyLine.Points.Clear();
                    editMode = EditMode.Path;
                }
                else
                {
                    newTracePolyLine.Points.Add(mCanvasPos);
                }
            } break;
            }
        }