Example #1
0
        private void SetObjectLenghtLabelValue()
        {
            string rulerLength = _polyRulerObject.GetRulerLengthAsString(_mapper.CalibrationScale);

            AnnUnit unit = _polyRulerObject.MeasurementUnit;

            if (unit == AnnUnit.SmartEnglish)
            {
                unit = AnnUnit.Inch;
            }

            string unitAbbrev = _polyRulerObject.UnitsAbbreviation[unit];

            if (_polyRulerObject.MeasurementUnit == AnnUnit.SmartMetric)
            {
                //remove unit abbreviation from ruler length string
                rulerLength = rulerLength.TrimEnd(_polyRulerObject.UnitsAbbreviation[AnnUnit.Meter].ToCharArray());
                rulerLength = rulerLength.TrimEnd(_polyRulerObject.UnitsAbbreviation[AnnUnit.Centimeter].ToCharArray());
                rulerLength = rulerLength.TrimEnd(_polyRulerObject.UnitsAbbreviation[AnnUnit.Millimeter].ToCharArray());
                rulerLength = rulerLength.TrimEnd(_polyRulerObject.UnitsAbbreviation[AnnUnit.Micrometer].ToCharArray());
            }

            //remove unit abbreviation from ruler length string
            rulerLength = rulerLength.TrimEnd(unitAbbrev.ToCharArray());

            _txtRulerLength.Text = rulerLength;
        }
Example #2
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;
            }
        }
Example #3
0
        void measurementUnitInfo_ValueChanged(object oldValue, object newValue)
        {
            AnnPolyRulerObject annPolyRulerObject = _annObject as AnnPolyRulerObject;

            if (annPolyRulerObject != null)
            {
                AnnUnit newMeasurementUnit = (AnnUnit)Enum.Parse(typeof(AnnUnit), (string)this.Properties["MeasurementUnit"].Values[(string)newValue]);
                annPolyRulerObject.MeasurementUnit = newMeasurementUnit;

                if (OnPropertyChanged != null)
                {
                    OnPropertyChanged("MeasurementUnit", newValue);
                }
            }
        }
Example #4
0
        private void UpdateObjectsInsideSelection(AnnSelectionObject selection, string propertyName)
        {
            propertyChangedCounter++;

            if (propertyName == "FixedStateOperations")
            {
                selection.FixedStateOperations = _targetObject.FixedStateOperations;
            }

            if (propertyName == "Name" && _tabControlObjectProperties.SelectedIndex == 0) // double check that we are in common tab , to avoid confliction between label font and text object font
            {
                foreach (AnnObject annObject in selection.SelectedObjects)
                {
                    if (annObject != _targetObject)
                    {
                        if (annObject.Labels.ContainsKey("AnnObjectName"))
                        {
                            annObject.Labels["AnnObjectName"] = _targetObject.Labels["AnnObjectName"].Clone();
                        }
                    }
                }
            }
            else if (propertyName == "UnitsAbbreviation")
            {
                AnnPolyRulerObject targetPolyRuler = _targetObject as AnnPolyRulerObject;
                if (targetPolyRuler != null)
                {
                    foreach (AnnObject annObject in selection.SelectedObjects)
                    {
                        AnnPolyRulerObject polyRuler = annObject as AnnPolyRulerObject;
                        if (polyRuler != null)
                        {
                            AnnUnit[] units = new AnnUnit[targetPolyRuler.UnitsAbbreviation.Keys.Count];
                            targetPolyRuler.UnitsAbbreviation.Keys.CopyTo(units, 0);
                            foreach (AnnUnit unit in units)
                            {
                                polyRuler.UnitsAbbreviation[unit] = targetPolyRuler.UnitsAbbreviation[unit];
                            }
                        }
                    }
                }
            }
            else
            {
                SetPolyRulerTickMarks(_targetObject);

                Type         srcType         = _targetObject.GetType();
                PropertyInfo srcPropertyInfo = srcType.GetProperty(propertyName);
                if (srcPropertyInfo != null)
                {
                    object newValue = srcPropertyInfo.GetValue(_targetObject, null);

                    foreach (AnnObject annObject in selection.SelectedObjects)
                    {
                        if (annObject != _targetObject)
                        {
                            if (annObject.Id == AnnObject.HiliteObjectId && propertyName == "Fill")
                            {
                                (annObject as AnnHiliteObject).HiliteColor = (newValue as AnnSolidColorBrush).Color;
                            }
                            if (annObject is AnnRectangleObject && propertyName == "HiliteColor")
                            {
                                (annObject as AnnRectangleObject).Fill = AnnSolidColorBrush.Create((newValue as string));
                            }

                            Type         destType         = annObject.GetType();
                            PropertyInfo destPropertyInfo = destType.GetProperty(propertyName);
                            if (destPropertyInfo != null)
                            {
                                if (propertyName == "Stroke")
                                {
                                    annObject.Stroke = (newValue as AnnStroke).Clone();
                                    SetPolyRulerTickMarks(annObject);
                                }
                                else
                                {
                                    destPropertyInfo.SetValue(annObject, newValue, null);
                                }
                            }
                        }
                    }
                }
            }

            propertyChangedCounter--;
        }