Пример #1
0
        /// <summary>
        /// Executed upon existing the param_expr rule
        /// </summary>
        /// <param name="context">the param_expr context</param>
        public override void ExitParam_expr([NotNull] ParamExprGrammarParser.Param_exprContext context)
        {
            base.ExitParam_expr(context);
            NodeProperty paramExprNodeProp = GetNodePropertyValue(context.expr());
            object       parValue          = paramExprNodeProp.nodePropertyValue;

            // Unique parameter value can only be "enforced" for a string datatype by appending a running number: <parValue> (#), starting with 2
            if (isUnique && parValue is string)
            {
                Tuple <string, object> key = new Tuple <string, object>(RevitParameterName, parValue);
                int counter = 0;
                if (UniqueParameterValue.TryGetValue(key, out counter))
                {
                    counter++;
                    parValue = parValue.ToString() + " (" + counter.ToString() + ")";
                    UniqueParameterValue[key] = counter;
                }
                else
                {
                    UniqueParameterValue.Add(key, 1);
                }
            }
            FinalParameterValue = parValue;
            UnitType            = paramExprNodeProp.uomTypeId;
            if (paramExprNodeProp.uomTypeId != null)
            {
                if (FinalParameterValue is double)
                {
                    double?paramValueDouble = FinalParameterValue as double?;
                    formattedValue      = UnitFormatUtils.Format(RevitElement.Document.GetUnits(), paramExprNodeProp.uomTypeId, paramValueDouble.Value, false);
                    FinalParameterValue = UnitUtils.ConvertToInternalUnits(paramValueDouble.Value, paramExprNodeProp.uomTypeId);
                }
            }
        }
Пример #2
0
 /// <summary>
 /// Executed upon entering param_expr rule
 /// </summary>
 /// <param name="context">the param_expr context</param>
 public override void EnterParam_expr([NotNull] ParamExprGrammarParser.Param_exprContext context)
 {
     base.EnterParam_expr(context);
     if (context.ChildCount == 4 && context.GetChild(0) is ITerminalNode && context.GetChild(0).GetText().Equals("U", StringComparison.CurrentCultureIgnoreCase))
     {
         // For unique value case, we will follow '<name>', '<name> (#)' with # as a running number. Unless the "formula" contains the RUNNINGNUMBER token
         // Here, we will make sure that we keep track the value to identify uniqueness
         isUnique = true;
     }
     else
     {
         isUnique = false;
     }
 }
Пример #3
0
        /// <summary>
        /// Executed upon existing the param_expr rule
        /// </summary>
        /// <param name="context">the param_expr context</param>
        public override void ExitParam_expr([NotNull] ParamExprGrammarParser.Param_exprContext context)
        {
            base.ExitParam_expr(context);
            object parValue = GetNodePropertyValue(context.expr()).nodePropertyValue;

            // Unique parameter value can only be "enforced" for a string datatype by appending a running number: <parValue> (#), starting with 2
            if (isUnique && parValue is string)
            {
                Tuple <string, object> key = new Tuple <string, object>(RevitParameterName, parValue);
                int counter = 0;
                if (UniqueParameterValue.TryGetValue(key, out counter))
                {
                    counter++;
                    parValue = parValue.ToString() + " (" + counter.ToString() + ")";
                    UniqueParameterValue[key] = counter;
                }
                else
                {
                    UniqueParameterValue.Add(key, 1);
                }
            }
            FinalParameterValue = parValue;
        }