Exemplo n.º 1
0
        public void Add(KeyValuePair <string, string> item)
        {
            // when not updating existing ParameterValue, we only
            // support creating StringParameterValue
            var pv = new StringParameterValue(item.Value);

            _parameterCollection.Add(item.Key, pv);
        }
Exemplo n.º 2
0
        private static ParameterSet ConvertToParameterSet(TlcModule.SweepableParamAttribute[] hps,
                                                          RecipeInference.SuggestedRecipe.SuggestedLearner learner)
        {
            if (learner.PipelineNode.HyperSweeperParamSet != null)
            {
                return(learner.PipelineNode.HyperSweeperParamSet);
            }

            var paramValues = new IParameterValue[hps.Length];

            if (hps.Any(p => p.RawValue == null))
            {
                PopulateSweepableParams(learner);
            }

            for (int i = 0; i < hps.Length; i++)
            {
                Contracts.CheckValue(hps[i].RawValue, nameof(TlcModule.SweepableParamAttribute.RawValue));

                switch (hps[i])
                {
                case TlcModule.SweepableDiscreteParamAttribute dp:
                    var learnerVal =
                        learner.PipelineNode.GetPropertyValueByName(dp.Name, (IComparable)dp.Options[0]);
                    var optionIndex = (int)(dp.RawValue ?? dp.IndexOf(learnerVal));
                    paramValues[i] = new StringParameterValue(dp.Name, dp.Options[optionIndex].ToString());
                    break;

                case TlcModule.SweepableFloatParamAttribute fp:
                    paramValues[i] =
                        new FloatParameterValue(fp.Name,
                                                (float)(fp.RawValue ?? learner.PipelineNode.GetPropertyValueByName(fp.Name, 0f)));
                    break;

                case TlcModule.SweepableLongParamAttribute lp:
                    paramValues[i] =
                        new LongParameterValue(lp.Name,
                                               (long)(lp.RawValue ?? learner.PipelineNode.GetPropertyValueByName(lp.Name, 0L)));
                    break;
                }
            }

            learner.PipelineNode.HyperSweeperParamSet = new ParameterSet(paramValues);
            return(learner.PipelineNode.HyperSweeperParamSet);
        }
Exemplo n.º 3
0
        public void TestStringParameterValue()
        {
            StringParameterValue value1          = new StringParameterValue(nameof(value1), "1");
            StringParameterValue value2          = new StringParameterValue(nameof(value2), "2");
            StringParameterValue duplicateValue1 = new StringParameterValue(nameof(value1), "1");

            Assert.False(value1.Equals(value2));
            Assert.True(value1.Equals(value1));
            Assert.True(value1.Equals(duplicateValue1));
            Assert.False(value1.Equals((object)value2));
            Assert.True(value1.Equals((object)value1));
            Assert.True(value1.Equals((object)duplicateValue1));

            Assert.False(value1.Equals(new LongParameterValue(nameof(value1), 1)));
            Assert.False(value1.Equals((IParameterValue)null));
            Assert.False(value1.Equals((object)null));
            Assert.False(value1.Equals(new object()));

            Assert.Equal(value1.GetHashCode(), value1.GetHashCode());
            Assert.Equal(value1.GetHashCode(), duplicateValue1.GetHashCode());
        }
Exemplo n.º 4
0
        public void TestParameterSetEquality()
        {
            LongParameterValue   value1       = new LongParameterValue(nameof(value1), 1);
            LongParameterValue   value2       = new LongParameterValue(nameof(value2), 2);
            StringParameterValue stringValue1 = new StringParameterValue(nameof(value1), "1");

            var parameterSet = new ParameterSet(new[] { value1 });

            Assert.False(parameterSet.Equals(null));

            // Verify Equals for sets with different hash codes
            var parameterSetNewHash = new ParameterSet(new IParameterValue[] { value1 }.ToDictionary(x => x.Name), hash: parameterSet.GetHashCode() + 1);

            Assert.NotEqual(parameterSet.GetHashCode(), parameterSetNewHash.GetHashCode());
            Assert.False(parameterSet.Equals(parameterSetNewHash));

            // Verify Equals for sets with the same hash code, but different number of values
            var parameterSetMoreValues = new ParameterSet(new IParameterValue[] { value1, value2 }.ToDictionary(x => x.Name), hash: parameterSet.GetHashCode());

            Assert.Equal(parameterSet.GetHashCode(), parameterSetMoreValues.GetHashCode());
            Assert.False(parameterSet.Equals(parameterSetMoreValues));

            // Verify Equals for sets with the same hash and item counts, but one of the items has a different name
            var parameterSetDifferentName = new ParameterSet(new IParameterValue[] { value2 }.ToDictionary(x => x.Name), hash: parameterSet.GetHashCode());

            Assert.Equal(parameterSet.GetHashCode(), parameterSetDifferentName.GetHashCode());
            Assert.False(parameterSet.Equals(parameterSetDifferentName));

            // Verify Equals for sets with the same hash and item names, but one of the items has a different value
            var parameterSetDifferentValue = new ParameterSet(new IParameterValue[] { stringValue1 }.ToDictionary(x => x.Name), hash: parameterSet.GetHashCode());

            Assert.Equal(parameterSet.GetHashCode(), parameterSetDifferentValue.GetHashCode());
            Assert.False(parameterSet.Equals(parameterSetDifferentValue));

            // Verify Equals for sets with the same hash and items
            var parameterSetSameHash = new ParameterSet(new IParameterValue[] { value1 }.ToDictionary(x => x.Name), hash: parameterSet.GetHashCode());

            Assert.Equal(parameterSet.GetHashCode(), parameterSetSameHash.GetHashCode());
            Assert.True(parameterSet.Equals(parameterSetSameHash));
        }
Exemplo n.º 5
0
        internal RemoteGlobalParameter(GlobalParameter parameter, Units units)
        {
            Name  = parameter.Name;
            Type  = string.Empty;
            Value = string.Empty;

            if (parameter.GetValue().GetType() == typeof(StringParameterValue))
            {
                StringParameterValue dvalue = parameter.GetValue() as StringParameterValue;
                Type  = "Text";
                Value = dvalue.Value;
            }
            else if (parameter.GetValue().GetType() == typeof(IntegerParameterValue))
            {
                IntegerParameterValue dvalue = parameter.GetValue() as IntegerParameterValue;
                Type  = "Integer";
                Value = dvalue.Value.ToString();
            }
            else if (parameter.GetValue().GetType() == typeof(DoubleParameterValue))
            {
                UnitType        utype = parameter.GetDefinition().UnitType;
                DisplayUnitType dunit = units.GetFormatOptions(utype).DisplayUnits;

                DoubleParameterValue dvalue = parameter.GetValue() as DoubleParameterValue;
                Type  = "Number";
                Value = UnitUtils.ConvertFromInternalUnits(dvalue.Value, dunit).ToString();
            }
            else if (parameter.GetValue().GetType() == typeof(ElementIdParameterValue))
            {
                ElementIdParameterValue dvalue = parameter.GetValue() as ElementIdParameterValue;
                Type = "Element";
                if (dvalue.Value.ToString() != "-1")
                {
                    string elementname = parameter.Document.GetElement(dvalue.Value).Name;
                    Value = elementname;
                }
            }
        }
Exemplo n.º 6
0
 public string this[string key]
 {
     get
     {
         var pv = _parameterCollection[key];
         var s  = ParameterValueToString(pv);
         return(s);
     }
     set
     {
         ParameterValue pv;
         if (_parameterCollection.TryGetValue(key, out pv))
         {
             UpdateParameterValue(pv, value);
         }
         else
         {
             // if not updating existing ParameterValue, we only
             // support creating StringParameterValue
             pv = new StringParameterValue(value);
         }
         _parameterCollection[key] = pv;
     }
 }
Exemplo n.º 7
0
        /// <summary>
        /// Return Global Parameter Value
        /// </summary>
        /// <param name="parameter"></param>
        /// <param name="doc"></param>
        /// <returns></returns>
        public static string GetAssGlobalParameterValue(this Parameter parameter, Document doc)
        {
            Dictionary <string, string> gloDictionary = new Dictionary <string, string>();
            ElementId elementId = parameter.GetAssociatedGlobalParameter();

            if (elementId != null)
            {
                if (doc.GetElement(elementId) is GlobalParameter globalParameter)
                {
                    DoubleParameterValue doublevalue = globalParameter.GetValue() as DoubleParameterValue;
                    StringParameterValue strpra      = globalParameter.GetValue() as StringParameterValue;
                    if (doublevalue != null)
                    {
                        return(RealString(doublevalue.Value));
                    }
                    if (strpra != null)
                    {
                        return(strpra.Value);
                    }
                    return(string.Empty);
                }
            }
            return(string.Empty);
        }
Exemplo n.º 8
0
        public FinishForm(Document Doc)
        {
            this.doc = Doc;
            if (GlobalParametersManager.FindByName(doc, "FinData") != ElementId.InvalidElementId)
            {
                GlobalParameter GlobePar2 = doc.GetElement(GlobalParametersManager.FindByName(doc, "FinData")) as GlobalParameter;

                StringParameterValue strPar = GlobePar2.GetValue() as StringParameterValue;
                String GPar = strPar.Value;
                wTypeBoxes = GPar.Split('|').ToList();
            }

            PhaseArray     xcom       = doc.Phases;
            List <Element> walltypes1 = new FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Walls).WhereElementIsElementType().ToList();

            walltypes1 = walltypes1.OrderBy(x => x.Name).ToList();
            List <Element> walltypes2 = walltypes1.Select(x => x).ToList();
            List <Element> walltypes3 = walltypes1.Select(x => x).ToList();



            //xcom.


            //PhaseSelector.SelectedItem = xcom;

            InitializeComponent();
            comboBox1.DataSource    = walltypes1;
            comboBox1.DisplayMember = "Name";
            comboBox1.ValueMember   = "Id";

            try
            {
                comboBox1.SelectedIndex = walltypes1.IndexOf(walltypes1.First(x => x.Name == wTypeBoxes[0]));
            }
            catch (Exception)
            {
            }


            LocFinSelector.DataSource    = walltypes2;
            LocFinSelector.DisplayMember = "Name";
            LocFinSelector.ValueMember   = "Id";
            try
            {
                LocFinSelector.SelectedIndex = walltypes2.IndexOf(walltypes2.First(x => x.Name == wTypeBoxes[1]));
            }
            catch (Exception)
            {
            }
            ColumnFinSelector.DataSource    = walltypes3;
            ColumnFinSelector.DisplayMember = "Name";
            ColumnFinSelector.ValueMember   = "Id";
            try
            {
                ColumnFinSelector.SelectedIndex = walltypes3.IndexOf(walltypes3.First(x => x.Name == wTypeBoxes[2]));
            }
            catch (Exception)
            {
            }

            PhaseSelector.DataSource    = xcom as IList <Phase>;
            PhaseSelector.DisplayMember = "Name";
            PhaseSelector.ValueMember   = "Id";
            foreach (Phase item in xcom)
            {
                PhaseSelector.Items.Add(item);
            }
            PhaseSelector.SelectedIndex = xcom.Size - 1;
        }
Exemplo n.º 9
0
        internal string EditParameter(Document doc, string name, string value)
        {
            try
            {
                IList <ElementId> globalparamids = GlobalParametersManager.GetGlobalParametersOrdered(doc);

                foreach (ElementId gid in globalparamids)
                {
                    GlobalParameter parameter = doc.GetElement(gid) as GlobalParameter;
                    if (!GlobalParametersManager.IsValidGlobalParameter(doc, parameter.Id))
                    {
                        continue;
                    }
                    if (parameter.IsDrivenByFormula)
                    {
                        continue;
                    }
                    if (parameter.Name == name)
                    {
                        if (parameter.GetValue().GetType() == typeof(StringParameterValue))
                        {
                            StringParameterValue dvalue = parameter.GetValue() as StringParameterValue;
                            dvalue.Value = value;
                            parameter.SetValue(dvalue);
                        }
                        else if (parameter.GetValue().GetType() == typeof(IntegerParameterValue))
                        {
                            if (value == "Yes")
                            {
                                value = "1";
                            }
                            else
                            {
                                value = "0";
                            }
                            IntegerParameterValue dvalue = parameter.GetValue() as IntegerParameterValue;
                            dvalue.Value = int.Parse(value);
                            parameter.SetValue(dvalue);
                        }
                        else if (parameter.GetValue().GetType() == typeof(DoubleParameterValue))
                        {
                            DoubleParameterValue dvalue = parameter.GetValue() as DoubleParameterValue;
                            UnitType             utype  = parameter.GetDefinition().UnitType;
                            DisplayUnitType      dunit  = Units.GetFormatOptions(utype).DisplayUnits;
                            double dp = double.Parse(value);
                            dvalue.Value = UnitUtils.ConvertToInternalUnits(dp, dunit);
                            parameter.SetValue(dvalue);
                        }
                        else if (parameter.GetValue().GetType() == typeof(ElementIdParameterValue))
                        {
                            ElementIdParameterValue dvalue = parameter.GetValue() as ElementIdParameterValue;

                            ElementId mat = FindMaterialByName(doc, value);

                            if (mat != null)
                            {
                                dvalue.Value = mat;
                                parameter.SetValue(dvalue);
                            }
                        }
                    }
                }
                return(value);
            }
            catch (Exception e)
            {
                return(e.Message);
            }
        }