Пример #1
0
        public static ParameterSettings AddParameterLinks(this ParameterSettings parameterSettings, Type type, IEnumerable <IParameterLink> parameterLinks, bool merge = true)
        {
            if (parameterSettings == null)
            {
                return(null);
            }

            if (type == null || parameterLinks == null || parameterLinks.Count() == 0)
            {
                return(parameterSettings);
            }

            ParameterSettings cloneSettings = parameterSettings.ShallowClone();

            cloneSettings.ParameterMaps = new List <ParameterMap>(parameterSettings.ParameterMaps);

            ParameterMap parameterMap = cloneSettings.ParameterMap(type);

            if (parameterMap == null)
            {
                cloneSettings.ParameterMaps.Add(new ParameterMap {
                    Type = type, ParameterLinks = new List <IParameterLink>(parameterLinks)
                });
            }
            else
            {
                cloneSettings.ParameterMaps.Remove(parameterMap);
                cloneSettings.ParameterMaps.Add(parameterMap.AddParameterLinks(parameterLinks, merge));
            }

            return(cloneSettings);
        }
Пример #2
0
        public static ParameterSettings RemoveParameterLinks(this ParameterSettings parameterSettings, Type type, IEnumerable <string> propertyNames)
        {
            if (parameterSettings == null)
            {
                return(null);
            }

            if (type == null || propertyNames == null || propertyNames.Count() == 0)
            {
                return(parameterSettings);
            }

            ParameterMap parameterMap = parameterSettings.ParameterMaps.Find(x => x.Type == type);

            if (parameterMap == null)
            {
                return(parameterSettings);
            }

            ParameterSettings cloneSettings = parameterSettings.ShallowClone();

            cloneSettings.ParameterMaps = new List <ParameterMap>(parameterSettings.ParameterMaps);
            cloneSettings.ParameterMaps.Remove(parameterMap);
            cloneSettings.ParameterMaps.Add(parameterMap.RemoveParameterLinks(propertyNames));
            return(cloneSettings);
        }
        public static ParameterSettings DefaultParameterSettings()
        {
            ParameterSettings settings = new ParameterSettings().AddParameterMaps(BH.Engine.Library.Query.Library("ParameterMaps").Where(x => x is ParameterMap).Cast <ParameterMap>());

            settings.Name = "BH Default Parameter Settings";
            return(settings);
        }
Пример #4
0
        private static void AnalyzeNamedType(SymbolAnalysisContext context, [NotNull] ParameterSettings settings)
        {
            var type = (INamedTypeSymbol)context.Symbol;

            if (IsDelegate(type))
            {
                AnalyzeDelegate(type, context, settings);
            }
        }
Пример #5
0
        public void SaveParameterSettings(string outputFile, string profileParameter)
        {
            var regStorage = BuildStorage();
            ParameterSettings parameterSettings = new ParameterSettings(regStorage);

            parameterSettings.Parameters.Outputfile = outputFile;
            parameterSettings.Parameters.Profile    = profileParameter;
            parameterSettings.SaveData("");
        }
Пример #6
0
        public static ParameterMap ParameterMap(this ParameterSettings parameterSettings, Type type)
        {
            if (parameterSettings == null || parameterSettings.ParameterMaps == null)
            {
                return(null);
            }

            return(parameterSettings.ParameterMaps.Find(x => x != null && x.Type == type));
        }
Пример #7
0
            public ParameterCountInfo(BaseAnalysisContext <TTarget> context, [NotNull] ParameterSettings settings,
                                      bool isConstructor = false)
            {
                Guard.NotNull(settings, nameof(settings));

                Context            = context;
                this.settings      = settings;
                this.isConstructor = isConstructor;
            }
Пример #8
0
        private ParameterSettings LoadParameterSettings()
        {
            var regStorage        = BuildStorage();
            var parametersettings = new ParameterSettings(regStorage);

            parametersettings.LoadData(regStorage, "");

            return(parametersettings);
        }
Пример #9
0
        private static void AnalyzeProperty(SymbolAnalysisContext context, [NotNull] ParameterSettings settings)
        {
            var property = (IPropertySymbol)context.Symbol;

            if (property.IsIndexer && MemberRequiresAnalysis(property, context.CancellationToken))
            {
                var info = new ParameterCountInfo <ImmutableArray <IParameterSymbol> >(context.Wrap(property.Parameters), settings);

                AnalyzeParameters(info, property, "Indexer");
            }
        }
Пример #10
0
        private static void AnalyzeLocalFunction(OperationAnalysisContext context, [NotNull] ParameterSettings settings)
        {
            var operation = (ILocalFunctionOperation)context.Operation;

            string memberName = GetMemberName(operation.Symbol);

            var info = new ParameterCountInfo <ImmutableArray <IParameterSymbol> >(context.Wrap(operation.Symbol.Parameters),
                                                                                   settings);

            AnalyzeParameters(info, operation.Symbol, memberName);

            AnalyzeReturnType(context.Wrap(operation.Symbol.ReturnType), operation.Symbol, memberName);
        }
Пример #11
0
        public static ParameterSettings ParameterSettings(IEnumerable <ParameterMap> parameterMaps = null, string tagsParameter = "", string materialGradeParameter = "")
        {
            ParameterSettings parameterSettings = new ParameterSettings();

            if (parameterMaps != null)
            {
                parameterSettings = parameterSettings.AddParameterMaps(parameterMaps);
            }

            parameterSettings.TagsParameter          = tagsParameter;
            parameterSettings.MaterialGradeParameter = materialGradeParameter;

            return(parameterSettings);
        }
Пример #12
0
        public static IEnumerable <IParameterLink> ParameterLinks(this ParameterSettings parameterSettings, Type type, string propertyName)
        {
            if (parameterSettings == null || parameterSettings.ParameterMaps == null || type == null || string.IsNullOrWhiteSpace(propertyName))
            {
                return(null);
            }

            ParameterMap parameterMap = parameterSettings.ParameterMap(type);

            if (parameterMap == null)
            {
                return(null);
            }

            return(parameterMap.ParameterLinks(propertyName));
        }
Пример #13
0
        private static void AnalyzeDelegate([NotNull] INamedTypeSymbol type, SymbolAnalysisContext context,
                                            [NotNull] ParameterSettings settings)
        {
            IMethodSymbol method = type.DelegateInvokeMethod;

            if (method != null)
            {
                string typeName = $"Delegate '{type.Name}'";

                var info = new ParameterCountInfo <ImmutableArray <IParameterSymbol> >(context.Wrap(method.Parameters), settings);

                AnalyzeParameters(info, type, typeName);

                AnalyzeReturnType(context.Wrap(method.ReturnType), type, typeName);
            }
        }
Пример #14
0
        public static ParameterSettings AddParameterMaps(this ParameterSettings parameterSettings, IEnumerable <ParameterMap> parameterMaps, bool merge = true)
        {
            if (parameterSettings == null)
            {
                return(null);
            }

            if (parameterMaps == null || parameterMaps.Count() == 0)
            {
                return(parameterSettings);
            }

            ParameterSettings cloneSettings = parameterSettings.ShallowClone();

            if (cloneSettings.ParameterMaps == null)
            {
                cloneSettings.ParameterMaps = new List <ParameterMap>();
            }
            else
            {
                cloneSettings.ParameterMaps = new List <ParameterMap>(cloneSettings.ParameterMaps);
            }

            foreach (ParameterMap parameterMap in parameterMaps)
            {
                ParameterMap cloneMap = cloneSettings.ParameterMaps.Find(x => parameterMap.Type == x.Type);
                if (cloneMap == null)
                {
                    cloneSettings.ParameterMaps.Add(parameterMap);
                }
                else
                {
                    if (merge)
                    {
                        cloneSettings.ParameterMaps.Add(cloneMap.AddParameterLinks(parameterMap.ParameterLinks, true));
                    }
                    else
                    {
                        cloneSettings.ParameterMaps.Add(parameterMap);
                    }

                    cloneSettings.ParameterMaps.Remove(cloneMap);
                }
            }

            return(cloneSettings);
        }
Пример #15
0
        private static void RegisterCompilationStart([NotNull] CompilationStartAnalysisContext startContext)
        {
            Guard.NotNull(startContext, nameof(startContext));

            ParameterSettings settings = GetParameterSettings(startContext.Options, startContext.CancellationToken);

            startContext.RegisterSymbolAction(actionContext => AnalyzePropertyAction(actionContext, settings),
                                              SymbolKind.Property);

            startContext.RegisterSymbolAction(actionContext => AnalyzeMethodAction(actionContext, settings), SymbolKind.Method);

            startContext.RegisterSymbolAction(actionContext => AnalyzeNamedTypeAction(actionContext, settings),
                                              SymbolKind.NamedType);

            startContext.RegisterOperationAction(actionContext => AnalyzeLocalFunctionAction(actionContext, settings),
                                                 OperationKind.LocalFunction);
        }
Пример #16
0
        public static ParameterSettings RemoveParameterMaps(this ParameterSettings parameterSettings, IEnumerable <Type> types)
        {
            if (parameterSettings == null)
            {
                return(null);
            }

            if (parameterSettings.ParameterMaps == null)
            {
                return(parameterSettings);
            }

            ParameterSettings cloneSettings = parameterSettings.ShallowClone();

            cloneSettings.ParameterMaps = parameterSettings.ParameterMaps.Where(x => types.All(y => x.Type != y)).ToList();
            return(cloneSettings);
        }
 //This is for other classes to read parameter data.
 public ParameterSettings GetParameters()
 {
     String ParaPath = Application.StartupPath + "\\Parameters.para";
     FileStream FS = new FileStream(ParaPath, FileMode.Open, FileAccess.Read);
     StreamReader ReadPara = new StreamReader(FS);
     String Line = ReadPara.ReadLine();
     FS.Close();
     String[] Param = Line.Split(',');
     ParameterSettings paradata = new ParameterSettings();
     paradata.DataNoiseTheshold = Convert.ToDouble(Param[0]);
     paradata.MinScoreThreshold = Convert.ToDouble(Param[1]);
     paradata.MatchErrorEM = Convert.ToDouble(Param[2]);
     paradata.MolecularWeightLowerBound = Convert.ToInt32(Param[3]);
     paradata.MolecularWeightUpperBound = Convert.ToInt32(Param[4]);
     paradata.GroupingErrorEG = Convert.ToDouble(Param[5]);
     paradata.AdductToleranceEA = Convert.ToDouble(Param[6]);
     paradata.MinScanNumber = Convert.ToInt32(Param[7]);
     return paradata;
 }
Пример #18
0
        public static HashSet <string> ParameterNames(this ParameterSettings parameterSettings, Type type, string name, bool typeParameters = false)
        {
            if (parameterSettings == null || type == null || string.IsNullOrWhiteSpace(name))
            {
                return(null);
            }

            ParameterMap parameterMap = parameterSettings.ParameterMap(type);

            if (parameterMap == null || parameterMap.ParameterLinks == null)
            {
                return(null);
            }

            Type linkType = typeParameters ? typeof(ElementTypeParameterLink) : typeof(ElementParameterLink);
            IEnumerable <IParameterLink> parameterLinks = parameterMap.ParameterLinks.Where(x => x.PropertyName == name && x.GetType() == linkType);

            return(new HashSet <string>(parameterLinks.SelectMany(x => x.ParameterNames)));
        }
Пример #19
0
        private static void AnalyzeMethod(SymbolAnalysisContext context, [NotNull] ParameterSettings settings)
        {
            var method = (IMethodSymbol)context.Symbol;

            if (!method.IsPropertyOrEventAccessor() && MemberRequiresAnalysis(method, context.CancellationToken))
            {
                string memberName    = GetMemberName(method);
                bool   isConstructor = IsConstructor(method);

                var info = new ParameterCountInfo <ImmutableArray <IParameterSymbol> >(context.Wrap(method.Parameters), settings,
                                                                                       isConstructor);

                AnalyzeParameters(info, method, memberName);

                if (MethodCanReturnValue(method))
                {
                    AnalyzeReturnType(context.Wrap(method.ReturnType), method, memberName);
                }
            }
        }
Пример #20
0
        /***************************************************/
        /****              Public methods               ****/
        /***************************************************/

        public static void SetProperties(this IObject iObject, Element element, ParameterSettings settings = null)
        {
            if (iObject == null || settings == null || settings.ParameterMaps == null || settings.ParameterMaps.Count == 0 || element == null)
            {
                return;
            }

            Type type = iObject.GetType();

            IEnumerable <PropertyInfo> propertyInfos = type.MapPropertyInfos();

            if (propertyInfos == null || propertyInfos.Count() == 0)
            {
                return;
            }

            Element elementType = element.Document.GetElement(element.GetTypeId());

            foreach (PropertyInfo pInfo in propertyInfos)
            {
                HashSet <string> parameterNames = settings.ParameterNames(type, pInfo.Name, false);
                if (parameterNames != null && iObject.SetProperty(pInfo, element, parameterNames))
                {
                    continue;
                }

                if (elementType == null)
                {
                    continue;
                }

                parameterNames = settings.ParameterNames(type, pInfo.Name, true);
                if (parameterNames != null)
                {
                    iObject.SetProperty(pInfo, elementType, parameterNames);
                }
            }
        }
        public void SaveParameterSettings(string outputFile, string profileParameter, string originalFilePath)
        {
            var parameters = new Parameters();

            parameters.Outputfile       = outputFile;
            parameters.Profile          = profileParameter;
            parameters.OriginalFilePath = originalFilePath;

            if (!ParametersAreSet(parameters))
            {
                return;
            }

            var parameterSettings = new ParameterSettings {
                Parameters = parameters
            };
            var regStorage = BuildStorage();

            parameterSettings.SaveData(regStorage);
            _logger.Debug($"Saved Parameters into registry:\n" +
                          $"OutputFile: {outputFile}\n" +
                          $"Profile: {profileParameter}\n" +
                          $"OriginalFilePath: {originalFilePath}");
        }
Пример #22
0
        private void ParamSection()
        {
            if (PaddedBoxGS == null)
            {
                PaddedBoxGS = new GUIStyle((GUIStyle)"HelpBox")
                {
                    normal = ((GUIStyle)"GroupBox").normal, padding = new RectOffset(4, 4, 4, 4)
                }
            }
            ;

            if (PaddedGS == null)
            {
                PaddedGS = new GUIStyle(PaddedBoxGS)
                {
                    normal = ((GUIStyle)"MiniLabel").normal
                }
            }
            ;

            t.useGlobalParamSettings = EditorGUILayout.ToggleLeft("Use Global Settings", t.useGlobalParamSettings);

            showAdvancedParams[uid] = IndentedFoldout(new GUIContent("Adv. Parameter Settings"), showAdvancedParams[uid], 1);

            if (showAdvancedParams[uid])
            {
                var indenthold = EditorGUI.indentLevel;

                EditorGUI.indentLevel = 0;
                EditorGUILayout.BeginHorizontal();
                EditorGUILayout.GetControlRect(GUILayout.MinWidth(COL1));
                EditorGUILayout.LabelField(label_Interp, (GUIStyle)"MiniLabel", GUILayout.MaxWidth(COL2));
                EditorGUILayout.LabelField(label_Extrap, (GUIStyle)"MiniLabel", GUILayout.MaxWidth(COL3));
                EditorGUILayout.LabelField(label_Default, (GUIStyle)"MiniLabel", GUILayout.MaxWidth(COL4));
                EditorGUILayout.EndHorizontal();

                var defs = t.sharedParamDefaults;

                if (t.useGlobalParamSettings)
                {
                    EditorGUILayout.BeginHorizontal();
                    InspectorWidgets.MiniToggle(t, EditorGUILayout.GetControlRect(GUILayout.MinWidth(COL1)), new GUIContent("Ints"), ref defs.includeInts);
                    DrawInterp(AnimatorControllerParameterType.Int, ref defs.interpolateInts);
                    DrawExtrap(AnimatorControllerParameterType.Int, ref defs.extrapolateInts);
                    DrawDefaults(AnimatorControllerParameterType.Int, ref defs.defaultInt);
                    EditorGUILayout.EndHorizontal();

                    EditorGUILayout.BeginHorizontal();
                    InspectorWidgets.MiniToggle(t, EditorGUILayout.GetControlRect(GUILayout.MinWidth(COL1)), new GUIContent("Floats"), ref defs.includeFloats);
                    DrawInterp(AnimatorControllerParameterType.Float, ref defs.interpolateFloats);
                    DrawExtrap(AnimatorControllerParameterType.Float, ref defs.extrapolateFloats);
                    DrawDefaults(AnimatorControllerParameterType.Float, ref defs.defaultFloat);
                    EditorGUILayout.EndHorizontal();

                    EditorGUILayout.BeginHorizontal();
                    InspectorWidgets.MiniToggle(t, EditorGUILayout.GetControlRect(GUILayout.MinWidth(COL1)), new GUIContent("Bools"), ref defs.includeBools);
                    EditorGUILayout.GetControlRect(GUILayout.MaxWidth(COL2));
                    DrawExtrap(AnimatorControllerParameterType.Bool, ref defs.extrapolateBools);
                    DrawDefaults(AnimatorControllerParameterType.Bool, ref defs.defaultBool);
                    EditorGUILayout.EndHorizontal();

                    EditorGUILayout.BeginHorizontal();
                    var tr = EditorGUILayout.GetControlRect(GUILayout.MinWidth(COL1));
                    InspectorWidgets.MiniToggle(t, tr, triggerLabel, ref defs.includeTriggers);
                    if (t.sharedParamDefaults.includeTriggers)
                    {
                        GUI.DrawTexture(new Rect(tr)
                        {
                            x = 2, width = 16
                        }, EditorGUIUtility.FindTexture("console.warnicon"));
                    }
                    EditorGUILayout.GetControlRect(GUILayout.MaxWidth(COL2));
                    DrawExtrap(AnimatorControllerParameterType.Trigger, ref defs.extrapolateTriggers);
                    DrawDefaults(AnimatorControllerParameterType.Trigger, ref defs.defaultTrigger);
                    EditorGUILayout.EndHorizontal();
                }
                else
                {
                    var names = ParameterSettings.RebuildParamSettings(a, ref t.sharedParamSettings, ref t.paramCount, t.sharedParamDefaults);
                    serializedObject.Update();

                    var pms = t.sharedParamSettings;
                    for (int i = 0; i < t.paramCount; ++i)
                    {
                        var pm = pms[i];

                        EditorGUILayout.BeginHorizontal();

                        // Type Letter Box (left vertical)
                        EditorGUILayout.BeginVertical(PaddedBoxGS, GUILayout.MaxWidth(8));
                        TypeLabel(EditorGUILayout.GetControlRect(GUILayout.MaxWidth(12)), pm.paramType);

                        EditorGUILayout.EndVertical();

                        // Main Vertical (Right)
                        EditorGUILayout.BeginVertical((pm.include) ? PaddedBoxGS : PaddedGS);

                        EditorGUILayout.BeginHorizontal();

                        InspectorWidgets.MiniToggle(t, EditorGUILayout.GetControlRect(GUILayout.MinWidth(COL1)), new GUIContent(names[i]), ref pm.include);

                        EditorGUI.BeginDisabledGroup(!pm.include);
                        DrawInterp(pm.paramType, ref pm.interpolate);
                        DrawExtrap(pm.paramType, ref pm.extrapolate);
                        DrawDefaults(pm.paramType, ref pm.defaultValue);
                        EditorGUI.EndDisabledGroup();

                        EditorGUILayout.EndHorizontal();

                        // Compression Row
                        if (pm.include)
                        {
                            if (pm.paramType == AnimatorControllerParameterType.Float || pm.paramType == AnimatorControllerParameterType.Int)
                            {
                                var sharedPSs = serializedObject.FindProperty("sharedParamSettings");
                                var ps        = sharedPSs.GetArrayElementAtIndex(i);

                                var fcrusher = (pm.paramType == AnimatorControllerParameterType.Float) ? ps.FindPropertyRelative("fcrusher") : ps.FindPropertyRelative("icrusher");

                                var r = EditorGUILayout.GetControlRect(false, EditorGUI.GetPropertyHeight(fcrusher));

                                Rect rectCrusher = new Rect(r)
                                {
                                    height = 16
                                };
                                EditorGUI.PropertyField(rectCrusher, fcrusher);
                            }
                        }

                        // End Right Vertical
                        EditorGUILayout.EndVertical();

                        // End Parameter
                        EditorGUILayout.EndHorizontal();
                    }
                }

                EditorGUI.indentLevel = indenthold;
            }
        }
Пример #23
0
        public static RevitSettings RevitSettings(ConnectionSettings connectionSettings = null, FamilyLoadSettings familyLoadSettings = null, ParameterSettings parameterSettings = null, double distanceTolerance = BH.oM.Geometry.Tolerance.Distance, double angleTolerance = BH.oM.Geometry.Tolerance.Angle)
        {
            RevitSettings settings = new RevitSettings();

            if (connectionSettings != null)
            {
                settings.ConnectionSettings = connectionSettings;
            }

            if (familyLoadSettings != null)
            {
                settings.FamilyLoadSettings = familyLoadSettings;
            }

            if (parameterSettings != null)
            {
                settings.ParameterSettings = parameterSettings;
            }

            if (!double.IsNaN(distanceTolerance))
            {
                settings.DistanceTolerance = distanceTolerance;
            }

            if (!double.IsNaN(distanceTolerance))
            {
                settings.AngleTolerance = angleTolerance;
            }

            return(settings);
        }
Пример #24
0
        /***************************************************/

        public static Parameter LookupParameter(this Element element, ParameterSettings parameterSettings, Type type, string name, bool mustHaveValue = true)
        {
            if (element == null || parameterSettings == null || type == null)
            {
                return(null);
            }

            // Lookup element parameter.
            List <string> names = new List <string> {
                name
            };
            HashSet <string> paramNames = parameterSettings.ParameterNames(type, name, false);

            if (paramNames != null)
            {
                names.AddRange(paramNames);
            }

            foreach (string val in names)
            {
                Parameter parameter = element.LookupParameter(val);
                if (parameter == null)
                {
                    continue;
                }

                if (parameter.HasValue || !mustHaveValue)
                {
                    return(parameter);
                }
            }

            // Lookup element type parameter (if specified in parameterSettings).
            paramNames = parameterSettings.ParameterNames(type, name, true);
            if (paramNames == null || paramNames.Count == 0)
            {
                return(null);
            }

            Element elementType = element.Document.GetElement(element.GetTypeId());

            if (elementType == null)
            {
                return(null);
            }

            foreach (string val in paramNames)
            {
                Parameter parameter = elementType.LookupParameter(val);
                if (parameter == null)
                {
                    continue;
                }

                if (parameter.HasValue || !mustHaveValue)
                {
                    return(parameter);
                }
            }

            return(null);
        }
Пример #25
0
        /***************************************************/
        /****              Public methods               ****/
        /***************************************************/

        public static void CopyParameters(this IBHoMObject bHoMObject, Element element, ParameterSettings settings = null)
        {
            if (bHoMObject == null || element == null)
            {
                return;
            }

            List <RevitParameter> parameters = new List <RevitParameter>();

            oM.Adapters.Revit.Parameters.ParameterMap parameterMap = settings?.ParameterMap(bHoMObject.GetType());
            IEnumerable <IParameterLink> parameterLinks            = null;

            if (parameterMap != null)
            {
                Element elementType = element.Document.GetElement(element.GetTypeId());
                IEnumerable <IParameterLink> typeParameterLinks = parameterMap.ParameterLinks.Where(x => x is ElementTypeParameterLink);
                if (elementType != null && typeParameterLinks.Count() != 0)
                {
                    foreach (Parameter parameter in elementType.ParametersMap)
                    {
                        RevitParameter bHoMParameter = parameter.ParameterFromRevit(typeParameterLinks, true);
                        if (bHoMParameter != null)
                        {
                            parameters.Add(bHoMParameter);
                        }
                    }
                }

                parameterLinks = parameterMap.ParameterLinks.Where(x => !(x is ElementTypeParameterLink));
            }

            IEnumerable elementParams = element.ParametersMap;

            if (((Autodesk.Revit.DB.ParameterMap)elementParams).IsEmpty)
            {
                elementParams = element.Parameters;
            }

            foreach (Parameter parameter in elementParams)
            {
                parameters.Add(parameter.ParameterFromRevit(parameterLinks, false));
            }

            bHoMObject.Fragments.Add(new RevitPulledParameters(parameters));
        }