Exemplo n.º 1
0
        /// <summary>
        /// CalculateMirrorStepDirection figures out how the
        /// Motors should move based on the button that was
        /// clicked.
        /// </summary>
        /// <param name="buttonType">The Type of Button on the UpDown2D control that was clicked</param>
        /// <param name="stepMagnitude">The magnitude of the step to make</param>
        /// <returns>The value of the step for the mirror to make</returns>
        private Int32 CalculateMirrorStepDirection(UpDown2D.ButtonType buttonType, Int32 stepMagnitude)
        {
            //Declare a variable to return -- default to the
            //input value
            Int32 rtn = stepMagnitude;

            //Invert the Step if the button press Left or Up
            if (buttonType == UpDown2D.ButtonType.Left || buttonType == UpDown2D.ButtonType.Up)
            {
                rtn *= -1;
            }

            //Return the result
            return(rtn);
        }
Exemplo n.º 2
0
        /// <summary>
        /// MoveMirror moves the specified mirror by the input
        /// amount of steps.
        /// </summary>
        /// <param name="type">The Type of Button that was clicked</param>
        /// <param name="step">The amount that the Mirror should be moved</param>
        /// <returns>Boolean TRUE if the mirror was moved, FALSE otherwise</returns>
        private Boolean MoveMirror(UpDown2D.ButtonType type, Int32 step)
        {
            //Declare a variable to return
            Boolean rtn = false;

            //Set the cursor appropriately
            Mouse.OverrideCursor = Cursors.Wait;

            //If the mirror still isn't created, show an error.
            //Otherwise, move the mirror.
            if (this._mirror == null)
            {
                this._eventAggregator.GetEvent <ErrorMessageEvent>().Publish(Strings.HardwareNotDetected);
            }
            else
            {
                //Save the SecondsPerStep value in the NewSpectrumInfo
                this.NewSpectrumInfo.SecondsPerStep = this._mirror.SecondsPerStep;

                //Translate the ButtonType into a MirrorAxis
                MirrorAxis axis = MirrorAxis.X;

                if (type == UpDown2D.ButtonType.Up || type == UpDown2D.ButtonType.Down)
                {
                    axis = MirrorAxis.Y;
                }

                //Try to move the mirror
                try
                {
                    //Call the Move Method
                    this._mirror.Move(axis, step);

                    //Set the return value to True to indicate success
                    rtn = true;
                }
                catch (System.Exception e)
                {
                    MessageBox.Show(e.Message, Strings.Error, MessageBoxButton.OK, MessageBoxImage.Error);
                }
            }

            //Reset the Cursor
            Mouse.OverrideCursor = Cursors.Arrow;

            //Return the result
            return(rtn);
        }
Exemplo n.º 3
0
        /// <summary>
        /// HandleUpDownClickEvent does the work of figuring out
        /// if the extents are valid and moving the mirror.
        /// </summary>
        /// <param name="udType">The Type of UpDown2D Control that was clicked</param>
        /// <param name="buttonType">The Type of the Button that was clicked</param>
        /// <param name="step">The size of the step that should be applied</param>
        private void HandleUpDownClickEvent(UpDownType udType, UpDown2D.ButtonType buttonType, Int32 stepMagnitude)
        {
            //Calculate the direction the mirror needs to move
            Int32 mirrorStep = this.CalculateMirrorStepDirection(buttonType, stepMagnitude);

            //Calculate the way the extent will change
            Int32 extentStep = this.CalcuateNewExtentStepDirection(udType, buttonType, stepMagnitude);

            //Create variables to hold the current Extent values
            Int32 currXExtent = this._xExtent;
            Int32 currYExtent = this._yExtent;

            //If this is an X-Axis move, calculate the new X-Extent
            if (buttonType == UpDown2D.ButtonType.Left || buttonType == UpDown2D.ButtonType.Right)
            {
                currXExtent += extentStep;
            }

            //If this is a Y-Axis move, calculate the new Y-Extent
            else if (buttonType == UpDown2D.ButtonType.Up || buttonType == UpDown2D.ButtonType.Down)
            {
                currYExtent += extentStep;
            }

            //Recalculate the Rows and Columns and move the
            //Mirror if they are valid.  Otherwise, show a message
            //that says that the laser will be out of bounds
            if (this.CheckNewExtentValues(udType, currXExtent, currYExtent) == true)
            {
                //Move the Mirror and save the new values if
                //that occurs successfully
                if (this.MoveMirror(buttonType, mirrorStep) == true)
                {
                    //Save the new values if necessary
                    this.SetNewExtents(udType, currXExtent, currYExtent);

                    //Set the new Row and Column values
                    //in the NewSpectrumInfo object and UI
                    this.SetNewRowColumnValues(udType);
                }
            }
            else
            {
                this._eventAggregator.GetEvent <ErrorMessageEvent>().Publish(Strings.OutsideBoundary);
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// CalculateStepDirection determines how the step should be
        /// calculated based on the UpDown control clicked.
        /// </summary>
        /// <param name="udType">The Type of the UpDown2D clicked</param>
        /// <param name="buttonType">The Type of the button clicked</param>
        /// <param name="step">The magnitude of the step</param>
        /// <returns></returns>
        private Int32 CalcuateNewExtentStepDirection(UpDownType udType, UpDown2D.ButtonType buttonType, Int32 step)
        {
            //Declare a variable to return -- default
            //to input value
            Int32 rtn = step;

            //Invert the Step if the button press was Right or Down
            //on Initial UpDown2D or Left or Up on Final UpDown2D --
            //the square is getting smaller
            if ((udType == UpDownType.Initial && (buttonType == UpDown2D.ButtonType.Right || buttonType == UpDown2D.ButtonType.Down)) ||
                (udType == UpDownType.Final && (buttonType == UpDown2D.ButtonType.Left || buttonType == UpDown2D.ButtonType.Up)))
            {
                rtn *= -1;
            }

            //Return the result
            return(rtn);
        }