Пример #1
0
        private void scale_Click(object sender, RoutedEventArgs e)
        {
            Grid plottingGrid = contentGrid.Children[1] as Grid;

            SlopePlotCanvas currCanvas = null;

            if (plottingGrid != null)
            {
                currCanvas = plottingGrid.Children[3] as SlopePlotCanvas;
            }
            if (currCanvas == null)
            {
                return;
            }

            // Obtain currently selected scale MenuItem (if there is one)
            // and uncheck all scale MenuItems
            MenuItem oldScale = null;

            foreach (MenuItem scale in scaleList.Items)
            {
                if (scale.IsChecked)
                {
                    scale.IsChecked = false;
                    oldScale        = scale;
                }
            }

            // Cast sending scale MenuItem and set it to checked
            MenuItem newScale = sender as MenuItem;

            if (newScale != null)
            {
                newScale.IsChecked = true;
            }

            // If the new value is different from the previous,
            // or the user would like to specify a custom scale
            if (newScale != oldScale || newScale == scCustom)
            {
                // Select from list of default scales, or set Custom
                double desiredScale;
                switch (newScale.Name)
                {
                // 1000:1
                case "sc1000":
                    currCanvas.ScaleType = Scales.sc1000;
                    desiredScale         = 1000;
                    break;

                // 800:1
                case "sc800":
                    currCanvas.ScaleType = Scales.sc800;
                    desiredScale         = 800;
                    break;

                // 600:1
                case "sc600":
                    currCanvas.ScaleType = Scales.sc600;
                    desiredScale         = 600;
                    break;

                // 500:1
                case "sc500":
                    currCanvas.ScaleType = Scales.sc500;
                    desiredScale         = 500;
                    break;

                // 400:1
                case "sc400":
                    currCanvas.ScaleType = Scales.sc400;
                    desiredScale         = 400;
                    break;

                // 300:1
                case "sc300":
                    currCanvas.ScaleType = Scales.sc300;
                    desiredScale         = 300;
                    break;

                // 200:1
                case "sc200":
                    currCanvas.ScaleType = Scales.sc200;
                    desiredScale         = 200;
                    break;

                // 150:1
                case "sc150":
                    currCanvas.ScaleType = Scales.sc150;
                    desiredScale         = 150;
                    break;

                // 100:1
                case "sc100":
                    currCanvas.ScaleType = Scales.sc100;
                    desiredScale         = 100;
                    break;

                // 50:1
                case "sc50":
                    currCanvas.ScaleType = Scales.sc50;
                    desiredScale         = 50;
                    break;

                // 25:1
                case "sc25":
                    currCanvas.ScaleType = Scales.sc25;
                    desiredScale         = 25;
                    break;

                // 10:1
                case "sc10":
                    currCanvas.ScaleType = Scales.sc10;
                    desiredScale         = 10;
                    break;

                // 5:1
                case "sc5":
                    currCanvas.ScaleType = Scales.sc5;
                    desiredScale         = 5;
                    break;

                // 2:1
                case "sc2":
                    currCanvas.ScaleType = Scales.sc2;
                    desiredScale         = 2;
                    break;

                // 1:1
                case "sc1":
                    currCanvas.ScaleType = Scales.sc1;
                    desiredScale         = 1;
                    break;

                // Custom
                default:
                    // Create modal dialog box to prompt user for new scale
                    CustomScaleDialog dlg = new CustomScaleDialog(this);
                    dlg.ShowDialog();

                    // If the dialog returned OK, set new scale
                    if (dlg.DialogResult == true)
                    {
                        desiredScale         = Double.Parse(dlg.scale.Text);
                        currCanvas.ScaleType = Scales.Custom;
                    }
                    // If the dialog returned Cancel, reset to previous scale
                    else
                    {
                        desiredScale       = currCanvas.Scale;
                        newScale.IsChecked = false;
                        oldScale.IsChecked = true;
                    }

                    break;
                }
                // Zoom to desired scale and centre content WITHOUT zoom
                currCanvas.Zoom(currCanvas.Scale / desiredScale, new Point(0.5 * currCanvas.ActualHeight, 0.5 * currCanvas.ActualWidth));
                currCanvas.CentreAndFitExtents(false);
            }
        }
Пример #2
0
        private void scale_Click( object sender , RoutedEventArgs e )
        {
            Grid plottingGrid = contentGrid.Children[1] as Grid;

            SlopePlotCanvas currCanvas = null;
            if ( plottingGrid != null )
            {
                currCanvas = plottingGrid.Children[3] as SlopePlotCanvas;
            }
            if ( currCanvas == null ) return;

            // Obtain currently selected scale MenuItem (if there is one)
            // and uncheck all scale MenuItems
            MenuItem oldScale = null;
            foreach ( MenuItem scale in scaleList.Items )
            {
                if ( scale.IsChecked )
                {
                    scale.IsChecked = false;
                    oldScale = scale;
                }
            }

            // Cast sending scale MenuItem and set it to checked
            MenuItem newScale = sender as MenuItem;
            if ( newScale != null )
            {
                newScale.IsChecked = true;
            }

            // If the new value is different from the previous,
            // or the user would like to specify a custom scale
            if ( newScale != oldScale || newScale == scCustom )
            {
                // Select from list of default scales, or set Custom
                double desiredScale;
                switch ( newScale.Name )
                {
                    // 1000:1
                    case "sc1000":
                        currCanvas.ScaleType = Scales.sc1000;
                        desiredScale = 1000;
                        break;
                    // 800:1
                    case "sc800":
                        currCanvas.ScaleType = Scales.sc800;
                        desiredScale = 800;
                        break;

                    // 600:1
                    case "sc600":
                        currCanvas.ScaleType = Scales.sc600;
                        desiredScale = 600;
                        break;

                    // 500:1
                    case "sc500":
                        currCanvas.ScaleType = Scales.sc500;
                        desiredScale = 500;
                        break;

                    // 400:1
                    case "sc400":
                        currCanvas.ScaleType = Scales.sc400;
                        desiredScale = 400;
                        break;

                    // 300:1
                    case "sc300":
                        currCanvas.ScaleType = Scales.sc300;
                        desiredScale = 300;
                        break;

                    // 200:1
                    case "sc200":
                        currCanvas.ScaleType = Scales.sc200;
                        desiredScale = 200;
                        break;

                    // 150:1
                    case "sc150":
                        currCanvas.ScaleType = Scales.sc150;
                        desiredScale = 150;
                        break;

                    // 100:1
                    case "sc100":
                        currCanvas.ScaleType = Scales.sc100;
                        desiredScale = 100;
                        break;

                    // 50:1
                    case "sc50":
                        currCanvas.ScaleType = Scales.sc50;
                        desiredScale = 50;
                        break;

                    // 25:1
                    case "sc25":
                        currCanvas.ScaleType = Scales.sc25;
                        desiredScale = 25;
                        break;

                    // 10:1
                    case "sc10":
                        currCanvas.ScaleType = Scales.sc10;
                        desiredScale = 10;
                        break;

                    // 5:1
                    case "sc5":
                        currCanvas.ScaleType = Scales.sc5;
                        desiredScale = 5;
                        break;

                    // 2:1
                    case "sc2":
                        currCanvas.ScaleType = Scales.sc2;
                        desiredScale = 2;
                        break;

                    // 1:1
                    case "sc1":
                        currCanvas.ScaleType = Scales.sc1;
                        desiredScale = 1;
                        break;

                    // Custom
                    default:
                        // Create modal dialog box to prompt user for new scale
                        CustomScaleDialog dlg = new CustomScaleDialog( this );
                        dlg.ShowDialog();

                        // If the dialog returned OK, set new scale
                        if ( dlg.DialogResult == true )
                        {
                            desiredScale = Double.Parse( dlg.scale.Text );
                            currCanvas.ScaleType = Scales.Custom;
                        }
                        // If the dialog returned Cancel, reset to previous scale
                        else
                        {
                            desiredScale = currCanvas.Scale;
                            newScale.IsChecked = false;
                            oldScale.IsChecked = true;
                        }

                        break;
                }
                // Zoom to desired scale and centre content WITHOUT zoom
                currCanvas.Zoom( currCanvas.Scale / desiredScale , new Point( 0.5 * currCanvas.ActualHeight , 0.5 * currCanvas.ActualWidth ) );
                currCanvas.CentreAndFitExtents( false );
            }
        }