Exemplo n.º 1
0
        private bool IsRuleSetToRangeNone(RoutingPreferenceManager routingPreferenceManager, RoutingPreferenceRuleGroupType groupType, int index)
        {
            if (routingPreferenceManager.GetNumberOfRules(groupType) == 0)
            {
                return(false);
            }

            RoutingPreferenceRule rule = routingPreferenceManager.GetRule(groupType, index);

            if (rule.NumberOfCriteria == 0)
            {
                return(false);
            }

            PrimarySizeCriterion psc = rule.GetCriterion(0) as PrimarySizeCriterion;

            if (psc.IsEqual(PrimarySizeCriterion.None()))
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Create Xml from a RoutingPreferenceRule
        /// </summary>
        /// <param name="rule"></param>
        /// <param name="groupType"></param>
        /// <returns></returns>
        private XElement createXmlFromRoutingPreferenceRule(RoutingPreferenceRule rule, RoutingPreferenceRuleGroupType groupType)
        {
            XElement xRoutingPreferenceRule = new XElement(XName.Get("RoutingPreferenceRule"));

            xRoutingPreferenceRule.Add(new XAttribute(XName.Get("description"), rule.Description));
            xRoutingPreferenceRule.Add(new XAttribute(XName.Get("ruleGroup"), groupType.ToString()));
            if (rule.NumberOfCriteria >= 1)
            {
                PrimarySizeCriterion psc = rule.GetCriterion(0) as PrimarySizeCriterion;

                if (psc.IsEqual(PrimarySizeCriterion.All()))
                {
                    xRoutingPreferenceRule.Add(new XAttribute(XName.Get("minimumSize"), "All"));
                }
                else
                if (psc.IsEqual(PrimarySizeCriterion.None()))
                {
                    xRoutingPreferenceRule.Add(new XAttribute(XName.Get("minimumSize"), "None"));
                }
                else //Only specify "maximumSize" if not specifying "All" or "None" for minimum size, just like in the UI.
                {
                    xRoutingPreferenceRule.Add(new XAttribute(XName.Get("minimumSize"), (Convert.ConvertValueDocumentUnits(psc.MinimumSize, m_document)).ToString()));
                    xRoutingPreferenceRule.Add(new XAttribute(XName.Get("maximumSize"), (Convert.ConvertValueDocumentUnits(psc.MaximumSize, m_document)).ToString()));
                }
            }
            else
            {
                xRoutingPreferenceRule.Add(new XAttribute(XName.Get("minimumSize"), "All"));
            }

            if (groupType == RoutingPreferenceRuleGroupType.Segments)
            {
                xRoutingPreferenceRule.Add(new XAttribute(XName.Get("partName"), GetSegmentNameById(rule.MEPPartId)));
            }
            else
            {
                xRoutingPreferenceRule.Add(new XAttribute(XName.Get("partName"), GetFittingNameById(rule.MEPPartId)));
            }

            return(xRoutingPreferenceRule);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Create a RoutingPreferenceRule from Xml
        /// </summary>
        /// <param name="ruleXElement"></param>
        /// <param name="groupType"></param>
        /// <returns></returns>
        private RoutingPreferenceRule ParseRoutingPreferenceRuleFromXML(XElement ruleXElement, out RoutingPreferenceRuleGroupType groupType)
        {
            XAttribute xaDescription = null;
            XAttribute xaPartName    = null;
            XAttribute xaMinSize     = null;
            XAttribute xaMaxSize     = null;
            XAttribute xaGroup       = null;

            xaDescription = ruleXElement.Attribute(XName.Get("description"));
            xaPartName    = ruleXElement.Attribute(XName.Get("partName"));
            xaGroup       = ruleXElement.Attribute(XName.Get("ruleGroup"));
            xaMinSize     = ruleXElement.Attribute(XName.Get("minimumSize"));

            ElementId partId;

            bool r3 = Enum.TryParse <RoutingPreferenceRuleGroupType>(xaGroup.Value, out groupType);

            if (!r3)
            {
                throw new RoutingPreferenceDataException("Could not parse rule group type: " + xaGroup.Value);
            }

            string description = xaDescription.Value;

            if (groupType == RoutingPreferenceRuleGroupType.Segments)
            {
                partId = GetSegmentByName(xaPartName.Value);
            }
            else
            {
                partId = GetFittingByName(xaPartName.Value);
            }

            if (partId == ElementId.InvalidElementId)
            {
                throw new RoutingPreferenceDataException("Could not find MEP Part: " + xaPartName.Value + ".  Is this the correct family name, and is the correct family loaded?");
            }

            RoutingPreferenceRule rule = new RoutingPreferenceRule(partId, description);


            PrimarySizeCriterion sizeCriterion;

            if (string.Compare(xaMinSize.Value, "All", true) == 0) //If "All" or "None" are specified, set min and max values to documented "Max" values.
            {
                sizeCriterion = PrimarySizeCriterion.All();
            }
            else if (string.Compare(xaMinSize.Value, "None", true) == 0)
            {
                sizeCriterion = PrimarySizeCriterion.None();
            }
            else // "maximumSize" attribute is only needed if not specifying "All" or "None."
            {
                try
                {
                    xaMaxSize = ruleXElement.Attribute(XName.Get("maximumSize"));
                }
                catch (System.Exception)
                {
                    throw new RoutingPreferenceDataException("Cannot get maximumSize attribute in: " + ruleXElement.ToString());
                }
                double min, max;
                bool   r1 = double.TryParse(xaMinSize.Value, out min);
                bool   r2 = double.TryParse(xaMaxSize.Value, out max);
                if (!r1 || !r2)
                {
                    throw new RoutingPreferenceDataException("Could not parse size values: " + xaMinSize.Value + ", " + xaMaxSize.Value);
                }
                if (min > max)
                {
                    throw new RoutingPreferenceDataException("Invalid size range.");
                }

                min           = Convert.ConvertValueToFeet(min, m_document);
                max           = Convert.ConvertValueToFeet(max, m_document);
                sizeCriterion = new PrimarySizeCriterion(min, max);
            }

            rule.AddCriterion(sizeCriterion);

            return(rule);
        }