Example #1
0
        /// <summary>
        /// Configure a new <see cref="ScenarioConfiguration"/> with
        /// <see cref="ScenarioConfiguration.Contribution"/> and
        /// <see cref="ScenarioConfiguration.IsRelevant"/> taken from
        /// <paramref name="calculationScenario"/>.
        /// </summary>
        /// <param name="calculationScenario">The calculation scenario to take the values from.</param>
        /// <returns>A new <see cref="ScenarioConfiguration"/> with
        /// <see cref="ScenarioConfiguration.Contribution"/> and
        /// <see cref="ScenarioConfiguration.IsRelevant"/> set.</returns>
        /// <exception cref="ArgumentNullException">Thrown when <paramref name="calculationScenario"/> is <c>null</c>.</exception>
        public static ScenarioConfiguration ToScenarioConfiguration(this ICalculationScenario calculationScenario)
        {
            if (calculationScenario == null)
            {
                throw new ArgumentNullException(nameof(calculationScenario));
            }

            return(new ScenarioConfiguration
            {
                Contribution = calculationScenario.Contribution * 100,
                IsRelevant = calculationScenario.IsRelevant
            });
        }
 public bool PublicTrySetScenarioParameters(ScenarioConfiguration scenarioConfiguration, ICalculationScenario scenario)
 {
     return TrySetScenarioParameters(scenarioConfiguration, scenario);
 }
Example #3
0
        /// <summary>
        /// Assigns the <paramref name="scenarioConfiguration"/> parameters to the <paramref name="scenario"/>.
        /// </summary>
        /// <param name="scenarioConfiguration">The scenario configuration containing values for the parameters.</param>
        /// <param name="scenario">The input to assign the values to.</param>
        /// <returns><c>true</c> if no <paramref name="scenarioConfiguration"/> was given, or when
        /// the <paramref name="scenarioConfiguration"/> is not empty, <c>false</c> otherwise.</returns>
        protected bool TrySetScenarioParameters(ScenarioConfiguration scenarioConfiguration, ICalculationScenario scenario)
        {
            if (scenarioConfiguration == null)
            {
                return(true);
            }

            bool hasContribution = scenarioConfiguration.Contribution.HasValue;
            bool hasRelevance    = scenarioConfiguration.IsRelevant.HasValue;

            if (!hasContribution && !hasRelevance)
            {
                Log.LogCalculationConversionError(Resources.CalculationConfigurationImporter_TrySetScenarioParameters_Scenario_empty,
                                                  scenario.Name);
                return(false);
            }

            if (hasContribution)
            {
                double contribution = scenarioConfiguration.Contribution.Value;

                if (double.IsNaN(contribution))
                {
                    Log.LogCalculationConversionError(Resources.CalculationConfigurationImporter_TrySetScenarioParameters_ScenarioContribution_Invalid,
                                                      scenario.Name);
                    return(false);
                }

                scenario.Contribution = (RoundedDouble)(contribution / 100);
            }

            if (hasRelevance)
            {
                scenario.IsRelevant = scenarioConfiguration.IsRelevant.Value;
            }

            return(true);
        }
Example #4
0
        /// </structural_toolkit_2015>


        /// <structural_toolkit_2015>

        /// <summary>
        /// Calculates list of elements according to calculation scenario returned by cref="CreateCalculationScenario".
        /// </summary>
        /// <param name="listElementData">List of elements objects</param>
        /// <param name="parameters">Common parameters</param>
        /// <param name="maxNumberOfThreads">Maximal namber of threads.</param>
        /// <param name="server">Acces to cref="Server".</param>
        protected void CalculateElementList(List <ObjectDataBase> listElementData, CommonParametersBase parameters, int maxNumberOfThreads, Server.Server server)
        {
            ICalculationScenario scenario = EngineData.CreateCalculationScenario(parameters);

            int stepsCount = 0;

            foreach (Autodesk.Revit.DB.StructuralAssetClass material in server.GetSupportedMaterials())
            {
                foreach (BuiltInCategory category in server.GetSupportedCategories(material))
                {
                    List <ICalculationObject> scenarioList = scenario.CalculationScenarioList(category, material);
                    foreach (ICalculationObject calcObj in scenarioList)
                    {
                        foreach (ElementDataBase elemData in listElementData)
                        {
                            if (elemData.Category == category && elemData.Material == material && calcObj.Categories.Contains(elemData.Category))
                            {
                                if (calcObj.Type == CalculationObjectType.Element)
                                {
                                    stepsCount++;
                                }
                                else
                                {
                                    stepsCount += elemData.ListSectionData.Count;
                                }
                            }
                        }
                    }
                }
            }

            Autodesk.Revit.DB.CodeChecking.NotificationService.ProgressStart(Resources.ResourceManager.GetString("Calculation"), 100);
            int stepNbr = 0;

            if (maxNumberOfThreads < 2)
            {
                foreach (Autodesk.Revit.DB.StructuralAssetClass material in server.GetSupportedMaterials())
                {
                    foreach (BuiltInCategory category in server.GetSupportedCategories(material))
                    {
                        List <ObjectDataBase>     listElement  = GetListElementForCategory(category, material, listElementData);
                        List <ICalculationObject> scenarioList = scenario.CalculationScenarioList(category, material);
                        foreach (ICalculationObject calcObj in scenarioList)
                        {
                            calcObj.Parameters = parameters;
                        }
                        foreach (ObjectDataBase element in listElement)
                        {
                            bool errorOccured = false;
                            foreach (ICalculationObject calcObj in scenarioList)
                            {
                                if (calcObj.Categories.Contains(element.Category))
                                {
                                    if (calcObj.Type == CalculationObjectType.Element)
                                    {
                                        if (NotificationService.ProgressBreakInvoked())
                                        {
                                            break;
                                        }
                                        stepNbr++;
                                        if ((int)((stepNbr - 1) * 100 / stepsCount) != (int)(stepNbr * 100 / stepsCount))
                                        {
                                            NotificationService.ProgressStep(string.Format("{0:d}%", stepNbr * 100 / stepsCount));
                                        }
                                        if (!errorOccured || calcObj.ErrorResponse == ErrorResponse.RunOnError)
                                        {
                                            if (!calcObj.Run(element))
                                            {
                                                errorOccured = true;
                                            }
                                        }
                                    }
                                    else
                                    {
                                        List <SectionDataBase> listSections = (element as ElementDataBase).ListSectionData;
                                        int sectionSteps = listSections.Count;
                                        if (!errorOccured || calcObj.ErrorResponse == ErrorResponse.RunOnError)
                                        {
                                            foreach (SectionDataBase section in listSections)
                                            {
                                                if (NotificationService.ProgressBreakInvoked())
                                                {
                                                    break;
                                                }
                                                stepNbr++;
                                                sectionSteps--;
                                                if ((int)((stepNbr - 1) * 100 / stepsCount) != (int)(stepNbr * 100 / stepsCount))
                                                {
                                                    NotificationService.ProgressStep(string.Format("{0:d}%", stepNbr * 100 / stepsCount));
                                                }
                                                if (!calcObj.Run(section))
                                                {
                                                    errorOccured = true;
                                                    if (calcObj.ErrorResponse == ErrorResponse.SkipOnError)
                                                    {
                                                        break;
                                                    }
                                                }
                                            }
                                        }
                                        while (sectionSteps > 0)
                                        {
                                            stepNbr++;
                                            sectionSteps--;
                                            if ((int)((stepNbr - 1) * 100 / stepsCount) != (int)(stepNbr * 100 / stepsCount))
                                            {
                                                NotificationService.ProgressStep(string.Format("{0:d}%", stepNbr * 100 / stepsCount));
                                            }
                                        }
                                    }
                                }
                            }
                            if (NotificationService.ProgressBreakInvoked())
                            {
                                break;
                            }
                        }
                    }
                }
            }
            else
            {
                foreach (Autodesk.Revit.DB.StructuralAssetClass material in server.GetSupportedMaterials())
                {
                    foreach (BuiltInCategory category in server.GetSupportedCategories(material))
                    {
                        List <ObjectDataBase>     listElement  = GetListElementForCategory(category, material, listElementData);
                        List <ICalculationObject> scenarioList = scenario.CalculationScenarioList(category, material);
                        foreach (ICalculationObject calcObj in scenarioList)
                        {
                            calcObj.Parameters = parameters;
                        }
                        object oStepNbr = (object)stepNbr;
                        Parallel.ForEach(listElement, new ParallelOptions()
                        {
                            MaxDegreeOfParallelism = maxNumberOfThreads
                        }, (element, elLoopState) =>
                        {
                            bool errorOccured = false;
                            foreach (ICalculationObject calcObj in scenarioList)
                            {
                                if (calcObj.Categories.Contains(element.Category))
                                {
                                    if (calcObj.Type == CalculationObjectType.Element)
                                    {
                                        if (NotificationService.ProgressBreakInvoked())
                                        {
                                            elLoopState.Break();
                                        }
                                        lock (oStepNbr)
                                        {
                                            stepNbr++;
                                            if ((int)((stepNbr - 1) * 100 / stepsCount) != (int)(stepNbr * 100 / stepsCount))
                                            {
                                                NotificationService.ProgressStep(string.Format("{0:d}%", stepNbr * 100 / stepsCount));
                                            }
                                        }
                                        if (!errorOccured || calcObj.ErrorResponse == ErrorResponse.RunOnError)
                                        {
                                            if (!calcObj.Run(element))
                                            {
                                                errorOccured = true;
                                            }
                                        }
                                    }
                                    else
                                    {
                                        List <SectionDataBase> listSections = (element as ElementDataBase).ListSectionData;
                                        int sectionSteps = listSections.Count;
                                        if (!errorOccured || calcObj.ErrorResponse == ErrorResponse.RunOnError)
                                        {
                                            Parallel.ForEach(listSections, new ParallelOptions()
                                            {
                                                MaxDegreeOfParallelism = maxNumberOfThreads
                                            }, (section, secLoopState) =>
                                            {
                                                if (NotificationService.ProgressBreakInvoked())
                                                {
                                                    secLoopState.Break();
                                                }
                                                lock (oStepNbr)
                                                {
                                                    stepNbr++;
                                                    sectionSteps--;
                                                    if ((int)((stepNbr - 1) * 100 / stepsCount) != (int)(stepNbr * 100 / stepsCount))
                                                    {
                                                        NotificationService.ProgressStep(string.Format("{0:d}%", stepNbr * 100 / stepsCount));
                                                    }
                                                }
                                                if (!calcObj.Run(section))
                                                {
                                                    errorOccured = true;
                                                    if (calcObj.ErrorResponse == ErrorResponse.SkipOnError)
                                                    {
                                                        secLoopState.Break();
                                                    }
                                                }
                                            });
                                        }
                                        while (sectionSteps > 0)
                                        {
                                            stepNbr++;
                                            sectionSteps--;
                                            if ((int)((stepNbr - 1) * 100 / stepsCount) != (int)(stepNbr * 100 / stepsCount))
                                            {
                                                NotificationService.ProgressStep(string.Format("{0:d}%", stepNbr * 100 / stepsCount));
                                            }
                                        }
                                    }
                                }
                            }
                            if (NotificationService.ProgressBreakInvoked())
                            {
                                elLoopState.Break();
                            }
                        });
                    }
                }
            }
        }