Example #1
0
        private void ApplyCalibrate()
        {
            if (_isPixelUnit)
            {
                _polyRulerObject.MeasurementUnit = AnnUnit.SmartEnglish;
            }

            // the method _polyRulerObject.GetRulerLength() , gets the ruler length in AnnUnit.Unit so we need to convert it to current _polyRulerObject.MeasurementUnit with no calibration ratio
            LeadLengthD lengthInUnits = _polyRulerObject.GetRulerLength(1);

            double sourceLength = AnnUnitConverter.Convert(lengthInUnits.Value, AnnUnit.Unit, _polyRulerObject.MeasurementUnit);

            double destLength = 1;

            // check if the entered value is Number
            if (!double.TryParse(_txtRulerLength.Text, out destLength))
            {
                throw new Exception("Invalid Ruler Length Value");
            }

            if (sourceLength != 0 && destLength != 0)
            {
                AnnUnit destUnit = (AnnUnit)Enum.Parse(typeof(AnnUnit), _comboMesurementUnit.SelectedItem.ToString());

                if (_cboxApplyToAllRulers.Checked)
                {
                    _mapper.Calibrate(LeadLengthD.Create(sourceLength), _polyRulerObject.MeasurementUnit, LeadLengthD.Create(destLength), destUnit);

                    AnnAutomationManager manager = _automation.Manager;

                    //update all exisiting rulers to have the new calibration measurement unit
                    foreach (AnnObject annObject in _automation.Container.Children)
                    {
                        AnnPolyRulerObject polyRuler = annObject as AnnPolyRulerObject;
                        if (polyRuler != null)
                        {
                            polyRuler.MeasurementUnit = destUnit;
                        }
                    }
                }
                else
                {
                    _polyRulerObject.Calibrate(LeadLengthD.Create(sourceLength), _polyRulerObject.MeasurementUnit, LeadLengthD.Create(destLength), destUnit);
                }

                _polyRulerObject.MeasurementUnit = destUnit;
            }

            if (_isPixelUnit)
            {
                _polyRulerObject.MeasurementUnit = AnnUnit.Pixel;
            }
        }