Ejemplo n.º 1
0
        private void digestMaxAreaCBoxChange(object sender)
        {
            System.Windows.Controls.ComboBox cb = sender as System.Windows.Controls.ComboBox;
            string   strNewOpArea = cb.Text;
            UnitType clipUnit     = UnitType.UT_Area;
            Units    thisDocUnits = _doc.GetUnits();
            double   userNewMaxOpArea;

            UnitFormatUtils.TryParse(thisDocUnits, clipUnit, strNewOpArea,
                                     out userNewMaxOpArea);
            switch (cb.Name)
            {
            case "XOpMaxA":
                pfXOpArea.Text = userNewMaxOpArea.ToString();
                digestAreaEntry(pfXOpArea);
                YOpMaxA.Text = cb.Text;
                break;

            case "YOpMaxA":
                pfYOpArea.Text = userNewMaxOpArea.ToString();
                digestAreaEntry(pfYOpArea);
                XOpMaxA.Text = cb.Text;
                break;

            default:
                break;
            }
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="value"></param>
        /// <param name="result"></param>
        /// <returns></returns>
        private bool TryGetValue(string value, out double?result)
        {
            result = null;
            var s     = string.Empty;
            var match = Regex.Match(value, @"^[0-9\'\-\/\""\s]*", RegexOptions.IgnoreCase);

            if (match.Success)
            {
                s = match.Value.Trim();
            }

            if (string.IsNullOrEmpty(s))
            {
                return(false);
            }

            var verify = Regex.Match(s, @"^[0-9\'\-\/\""\s]*$", RegexOptions.IgnoreCase);

            if (!verify.Success)
            {
                return(false);
            }

            if (!UnitFormatUtils.TryParse(_doc.GetUnits(), UnitType.UT_Length, s,
                                          new ValueParsingOptions(),
                                          out var second))
            {
                return(false);
            }

            result = second;
            return(true);
        }
Ejemplo n.º 3
0
        bool IsParsed(string valParse, out double OutParse)
        {
            Units vUnits  = _Doc.GetUnits();
            bool  vResult = UnitFormatUtils.TryParse(vUnits, UnitType.UT_Length, valParse, out OutParse);

            return(vResult);
        }
        private void Window_Closing(object sender,
                                    System.ComponentModel.CancelEventArgs e)
        {
            String pfc = this.pfClip.Text;

            try
            {
                UnitType clipUnit     = UnitType.UT_Length;
                Units    thisDocUnits = _doc.GetUnits();
                double   userFarClipSetting;
                UnitFormatUtils.TryParse(thisDocUnits,
                                         clipUnit, pfc, out userFarClipSetting);
                Properties.Settings.Default.PreferFarClip = userFarClipSetting;
            }
            catch (Exception)
            {
                MessageBox.Show("For some unknown reason.\n\nNo change was made.",
                                "Settings Error");
            }
            Properties.Settings.Default.FormFarClip_Top  = this.Top;
            Properties.Settings.Default.FormFarClip_Left = this.Left;
            Properties.Settings.Default.FormFarClip_HT   = this.Height;
            Properties.Settings.Default.FormFarClip_WD   = this.Width;
            Properties.Settings.Default.Save();
        }
Ejemplo n.º 5
0
        private void digestAreaEntry(object sender)
        {
            System.Windows.Controls.TextBox tb = sender as System.Windows.Controls.TextBox;
            string   strNewOpArea = tb.Text;
            UnitType clipUnit     = UnitType.UT_Area;
            Units    thisDocUnits = _doc.GetUnits();
            double   userNewOpArea;

            UnitFormatUtils.TryParse(thisDocUnits, clipUnit, strNewOpArea,
                                     out userNewOpArea);
            switch (tb.Name)
            {
            case "pfXOpArea":
                YOpDist          = userNewOpArea / XOpDist;
                pfYdistance.Text = AsRevitDistanceFormat(YOpDist);
                break;

            case "pfYOpArea":
                XOpDist          = userNewOpArea / YOpDist;
                pfXdistance.Text = AsRevitDistanceFormat(XOpDist);
                break;

            default:
                break;
            }
            CalcOpArea();
            UpdateOpAreas();
            tb.CaretIndex = tb.Text.Length;  /// reset cursor to end of text
        }
Ejemplo n.º 6
0
            public static bool GetLengthInput(Document document, String userInputLength, out double dParsedLength)
            {
                dParsedLength = 0;
                Units units = document.GetUnits();

                // try to parse a user entered string (i.e. 100 mm, 1'6")
                return(UnitFormatUtils.TryParse(units, UnitType.UT_Length, userInputLength, out dParsedLength));
            }
Ejemplo n.º 7
0
            public static double String_FeetandInch2Double(Document Document, string FeetandInchs)
            {
                double dParsedLength = 0;
                Units  units         = Document.GetUnits();

                UnitFormatUtils.TryParse(units, UnitType.UT_Length, FeetandInchs, out dParsedLength);
                return(dParsedLength);
            }
Ejemplo n.º 8
0
        private double ConvertStringToFeetInch(string feetInchString)
        {
            double feetInch = 0;

            Units units = this.doc.GetUnits();

            if (!UnitFormatUtils.TryParse(units, UnitType.UT_Length, feetInchString, out feetInch))
            {
                throw new FormatException();
            }

            return(feetInch);
        }
Ejemplo n.º 9
0
        public static double?GetValueFromString(string text, Units units)
        {
            // Check the string value
            var heightValueString = text;

            if (UnitFormatUtils.TryParse(units, UnitType.UT_Length, heightValueString, out double length))
            {
                return(length);
            }
            else
            {
                return(null);
            }
        }
Ejemplo n.º 10
0
        private void pfArry_LostFocus(object sender, RoutedEventArgs e)
        {
            System.Windows.Controls.TextBox tb = sender as System.Windows.Controls.TextBox;
            String   pfc          = tb.Text;
            UnitType clipUnit     = UnitType.UT_Number;
            Units    thisDocUnits = _doc.GetUnits();
            double   userDistance;

            UnitFormatUtils.TryParse(thisDocUnits, clipUnit, pfc,
                                     out userDistance);
            if (userDistance > 1)
            {
                tb.Text = Convert.ToInt32(userDistance).ToString();
            }
            else
            {
                tb.Text = "2";
            }
        }
Ejemplo n.º 11
0
        //public void application_Sync(object sender, DocumentSynchronizingWithCentralEventArgs args)
        //{
        //    Document doc = args.Document;
        //progress.Report(doc);
        //}
        public void getdoc(object sender, ViewActivatedEventArgs args)
        {
            doc = args.Document;
            ComboBoxMemberData Range1 = new ComboBoxMemberData("0", "1/2\"");
            ComboBoxMemberData Range2 = new ComboBoxMemberData("1", "1\"");
            ComboBoxMemberData Range3 = new ComboBoxMemberData("2", "3\"");
            ComboBoxMemberData Range4 = new ComboBoxMemberData("3", "1' 0\"");
            ComboBoxMemberData Range5 = new ComboBoxMemberData("4", "3' 0\"");
            ComboBoxMemberData Range6 = new ComboBoxMemberData("5", "10' 0\"");

            if (doc.DisplayUnitSystem == DisplayUnit.IMPERIAL)
            {
                UnitFormatUtils.TryParse(doc.GetUnits(), UnitType.UT_Length, "1/2\"", out StoreExp.vrOpt1);
                UnitFormatUtils.TryParse(doc.GetUnits(), UnitType.UT_Length, "1\"", out StoreExp.vrOpt2);
                UnitFormatUtils.TryParse(doc.GetUnits(), UnitType.UT_Length, "3\"", out StoreExp.vrOpt3);
                UnitFormatUtils.TryParse(doc.GetUnits(), UnitType.UT_Length, "1'0\"", out StoreExp.vrOpt4);
                UnitFormatUtils.TryParse(doc.GetUnits(), UnitType.UT_Length, "3'0\"", out StoreExp.vrOpt5);
                UnitFormatUtils.TryParse(doc.GetUnits(), UnitType.UT_Length, "10'0\"", out StoreExp.vrOpt6);
            }
            else
            {
                UnitFormatUtils.TryParse(doc.GetUnits(), UnitType.UT_Length, "1 cm", out StoreExp.vrOpt1);
                UnitFormatUtils.TryParse(doc.GetUnits(), UnitType.UT_Length, "2 cm", out StoreExp.vrOpt2);
                UnitFormatUtils.TryParse(doc.GetUnits(), UnitType.UT_Length, "10 cm", out StoreExp.vrOpt3);
                UnitFormatUtils.TryParse(doc.GetUnits(), UnitType.UT_Length, "30 cm", out StoreExp.vrOpt4);
                UnitFormatUtils.TryParse(doc.GetUnits(), UnitType.UT_Length, "90 cm", out StoreExp.vrOpt5);
                UnitFormatUtils.TryParse(doc.GetUnits(), UnitType.UT_Length, "300 cm", out StoreExp.vrOpt6);
                Range1.Text = "1 cm"; Range2.Text = "2 cm"; Range3.Text = "10 cm";
                Range4.Text = "30 cm"; Range5.Text = "90 cm"; Range6.Text = "300 cm";
            }
            UiCtrApp.ViewActivated -= getdoc;
            foreach (RibbonItem item in panel_ViewSetup.GetItems())
            {
                if (item.Name == "ShiftRange")
                {
                    ComboBox ShiftRange_CB = (ComboBox)item;
                    ShiftRange_CB.AddItem(Range1); ShiftRange_CB.AddItem(Range2);
                    ShiftRange_CB.AddItem(Range3); ShiftRange_CB.AddItem(Range4);
                    ShiftRange_CB.AddItem(Range5); ShiftRange_CB.AddItem(Range6);
                }
            }
            doc = null;
        }
Ejemplo n.º 12
0
        private void SaveCurrentState()
        {
            String pfXop = pfXdistance.Text;
            String pfYop = pfYdistance.Text;
            String pfXa  = pfXArry.Text;
            String pfYa  = pfYArry.Text;

            try {
                UnitType opDistUnit   = UnitType.UT_Length;
                Units    thisDocUnits = _doc.GetUnits();

                double userX_OpDistance;
                UnitFormatUtils.TryParse(thisDocUnits, opDistUnit, pfXop, out userX_OpDistance);
                Properties.Settings.Default.X_OpDistance = userX_OpDistance;

                double userY_OpDistance;
                UnitFormatUtils.TryParse(thisDocUnits, opDistUnit, pfYop, out userY_OpDistance);
                Properties.Settings.Default.Y_OpDistance = userY_OpDistance;

                int XArry = Int32.Parse(pfXa);
                int YArry = Int32.Parse(pfYa);

                Properties.Settings.Default.X_ARY_QTY = XArry;
                Properties.Settings.Default.Y_ARY_QTY = YArry;

                Properties.Settings.Default.OpArea   = XOpMaxA.Text;
                Properties.Settings.Default.MaxSpace = MaxSpace.Text;

                Properties.Settings.Default.FormOps_Top  = Top;
                Properties.Settings.Default.FormOps_Left = Left;

                Properties.Settings.Default.SeeSmallRoom = (bool)SeeSmallRoom.IsChecked;
                Properties.Settings.Default.SeeMinDist   = (bool)SeeMinDist.IsChecked;

                //MessageBox.Show(Properties.Settings.Default.SeeSmallRoom.ToString() + "  |  " + Properties.Settings.Default.SeeMinDist.ToString());

                Properties.Settings.Default.Save();
            } catch (Exception) {
                MessageBox.Show("For some unknown reason.\n\nNo settings saved.",
                                "Settings Error");
            }
        }
Ejemplo n.º 13
0
        private void LengthTextBox_TextChanged()
        {
            if (_lenghtTextBoxIsFocused && !string.IsNullOrEmpty(LengthModel.SelectedText))
            {
                // run only if revit context injected
                if (_revitDocument != null && LengthModel.LengthRepresentation != null)
                {
                    Units docUnits          = _revitDocument.GetUnits();
                    ValueParsingOptions vpo = new ValueParsingOptions();
                    vpo.AllowedValues         = AllowedValues.NonNegative;
                    LengthModel.ParsingResult = UnitFormatUtils.TryParse(docUnits, UnitType.UT_Length,
                                                                         LengthModel.LengthRepresentation, vpo, out double output);

                    if (LengthModel.ParsingResult == true)
                    {
                        LengthModel.LengthInDouble = output;
                        output = output * 12 * 32;
                        output = Math.Round(output, MidpointRounding.AwayFromZero);
                        int outputInt = Convert.ToInt32(output);
                        int count     = LengthModel.ProperTextSelection.Length;
                        if (outputInt.ToString().Length > count)
                        {
                            LengthModel.ParsingResult      = false;
                            LengthModel.UpdatedCodedLength = new string('9', count);
                        }
                        else
                        {
                            LengthModel.UpdatedCodedLength = PadNumberWithLeadingZeros(outputInt, count);
                        }
                    }
                    else if (LengthModel.UpdatedCodedLength == null)
                    {
                        int count = LengthModel.ProperTextSelection.Length;
                        LengthModel.UpdatedCodedLength = new string('9', count);
                    }

                    //TO DO: Change event to PropertyChanged event. This one is redundant.
                    OnLengthParsed(EventArgs.Empty);
                }
            }
        }
 private void pfClip_KeyUp(object sender, KeyEventArgs e)
 {
     if (e.Key == Key.Return)
     {
         String   pfc          = this.pfClip.Text;
         UnitType clipUnit     = UnitType.UT_Length;
         Units    thisDocUnits = _doc.GetUnits();
         double   userFarClipSetting;
         UnitFormatUtils.TryParse(thisDocUnits, clipUnit, pfc,
                                  out userFarClipSetting);
         if (userFarClipSetting > 0)
         {
             this.pfClip.Text = UnitFormatUtils.Format(thisDocUnits,
                                                       clipUnit, userFarClipSetting, false, false);
         }
         else
         {
             this.pfClip.Text = "8' - 0\"";
         }
     }
 }
Ejemplo n.º 15
0
 public void UpdateLengthRepresentation()
 {
     //Check if in Revit context.
     if (_revitDocument != null)
     {
         Units docUnits          = _revitDocument.GetUnits();
         ValueParsingOptions vpo = new ValueParsingOptions();
         vpo.AllowedValues = AllowedValues.NonNegative;
         bool parsRes = UnitFormatUtils.TryParse(docUnits, UnitType.UT_Length,
                                                 LengthModel.LengthRepresentation, vpo, out double output);
         //If parsing succeded
         if (parsRes == true)
         {
             output = output * 12 * 32;
             output = Math.Round(output, 0, MidpointRounding.AwayFromZero);
             output = output / 12 / 32;
             LengthModel.LengthRepresentation = UnitFormatUtils.Format(
                 docUnits, UnitType.UT_Length, output, true, true);
         }
     }
 }
Ejemplo n.º 16
0
        private void SanityCheck()
        {
            Double   opArea       = XOpDist * YOpDist;
            String   strMaxArea   = XOpMaxA.Text;
            UnitType clipUnit     = UnitType.UT_Area;
            Units    thisDocUnits = _doc.GetUnits();
            double   userMaxOpArea;

            UnitFormatUtils.TryParse(thisDocUnits, clipUnit, strMaxArea,
                                     out userMaxOpArea);
            if (userMaxOpArea >= opArea)
            {
                Body.Background = ColorExt.ToBrush(System.Drawing.Color.AliceBlue);
            }
            else
            {
                Body.Background = ColorExt.ToBrush(System.Drawing.Color.LightPink);
                msg.Text        = "OpArea exceeds Max OpArea";
                return;
            }

            if (XOpDist < 6.0 || YOpDist < 6.0)
            {
                Body.Background = ColorExt.ToBrush(System.Drawing.Color.LightPink);
                msg.Text        = "Spacing smaller than 6'.";
                return;
            }
            double maxDist;

            if (Double.TryParse(MaxSpace.Text, out maxDist))
            {
                if (XOpDist > maxDist || YOpDist > maxDist)
                {
                    Body.Background = ColorExt.ToBrush(System.Drawing.Color.LightPink);
                    msg.Text        = "Spacing exceeds " + maxDist.ToString() + "'.";
                    return;
                }
            }
            msg.Text = "";
        }
Ejemplo n.º 17
0
        private void digestDistEntry(object sender)
        {
            System.Windows.Controls.TextBox tb = sender as System.Windows.Controls.TextBox;
            String   pfc          = tb.Text;
            UnitType clipUnit     = UnitType.UT_Length;
            Units    thisDocUnits = _doc.GetUnits();
            double   userDistance;

            UnitFormatUtils.TryParse(thisDocUnits, clipUnit, pfc,
                                     out userDistance);
            if (userDistance > 0)
            {
                tb.Text = AsRevitDistanceFormat(userDistance);
            }
            else
            {
                tb.Text = "15' - 0\"";
            }
            tb.CaretIndex = tb.Text.Length;  /// reset cursor to end of text
            UnitFormatUtils.TryParse(thisDocUnits, clipUnit, tb.Text,
                                     out userDistance);
            switch (tb.Name)
            {
            case "pfXdistance":
                XOpDist = userDistance;
                break;

            case "pfYdistance":
                YOpDist = userDistance;
                break;

            default:
                break;
            }
            CalcOpArea();
            UpdateOpAreas();
        }
Ejemplo n.º 18
0
 public static void ConvertLength(Document doc, string text, out double value)
 {
     value = (UnitFormatUtils.TryParse(doc.GetUnits(), UnitType.UT_Length, text, out double xValue)) ? xValue : 0;
 }
        public static double AngleDbl(ModelInfo info, string angle_str)
        {
            bool s = UnitFormatUtils.TryParse(info.DOC.GetUnits(), UnitTypeId.Degrees, angle_str, out double val);

            return(s ? val : -1);
        }
        public static double LengthDbl(ModelInfo info, string cvt_str)
        {
            bool s = UnitFormatUtils.TryParse(info.DOC.GetUnits(), UnitType.UT_Length, cvt_str, out double val);

            return(s ? val : -1);
        }