Пример #1
0
        /// <summary>
        /// Reads from Revit information about selected elements, next Calculates the list of elements, at the end saves calculation results in Revit Data Base.
        /// </summary>
        /// <param name="listElementStatus">List identyficators of elements with result status.</param>
        /// <param name="server">Acces to cref="Server".</param>
        /// <param name="data">Acces to cref="ServiceData".</param>
        protected void CalculateSetOfElements(List <Tuple <ElementId, ResultStatus> > listElementStatus, Server.Server server, Autodesk.Revit.DB.CodeChecking.ServiceData data)
        {
            // reading from Revit Api
            CommonParametersBase  parameters      = ReadCommonParameters(listElementStatus, server, data);
            List <ObjectDataBase> listElementData = ReadListElementData(data, listElementStatus, parameters);

            if (NotificationService.ProgressBreakInvoked() == false)
            {
                EngineData.ReadFromRevitDB(listElementData, parameters, data);
            }

            int maxNumberOfThreads = EngineData.GetNumberOfThreads(data);

            if (maxNumberOfThreads < 1)
            {
                maxNumberOfThreads = 1;
            }

            // pure calculation (without any connection with Revit api)
            List <ObjectDataBase> listElementFiltered = EngineData.FilterElementForCalculation(listElementData);

            if (NotificationService.ProgressBreakInvoked() == false)
            {
                /// <structural_toolkit_2015>
                CalculateElementList(listElementFiltered, parameters, maxNumberOfThreads, server);
            }
            /// </structural_toolkit_2015>

            // writing to Revit Api
            if (NotificationService.ProgressBreakInvoked() == false)
            {
                SaveListElementData(data, listElementData);
                EngineData.SaveToRevitDB(listElementData, parameters, data);
            }
        }
 /// <summary>
 /// Initializes a new instance of the CommonParametersBase from an existing one.
 /// </summary>
 /// <param name="param">Common parameters to copy.</param>
 public CommonParametersBase(CommonParametersBase param)
 {
     listElemStatus    = param.ListElementStatus;
     listCombId        = param.ListCombinationId;
     activePackageGuid = param.activePackageGuid;
     calcParams        = param.CalculationParameter;
 }
Пример #3
0
        /// </structural_toolkit_2015>

        /// <summary>
        /// Read from Revit parameters common for all selected elements and stores them in cref="CommonParametersBase".
        /// </summary>
        /// <param name="listElementStatus">List identyficators of elements with result status.</param>
        /// <param name="server">Acces to cref="Server".</param>
        /// <param name="data">Acces to cref="ServiceData".</param>
        /// <returns>Common parameters.</returns>
        protected CommonParametersBase ReadCommonParameters(List <Tuple <ElementId, ResultStatus> > listElementStatus, Server.Server server, Autodesk.Revit.DB.CodeChecking.ServiceData data)
        {
            Autodesk.Revit.DB.CodeChecking.Storage.StorageService  service         = Autodesk.Revit.DB.CodeChecking.Storage.StorageService.GetStorageService();
            Autodesk.Revit.DB.CodeChecking.Storage.StorageDocument storageDocument = service.GetStorageDocument(data.Document);

            Guid activePackageId = storageDocument.CalculationParamsManager.CalculationParams.GetInputResultPackageId(server.GetServerId());

            Autodesk.Revit.DB.ExtensibleStorage.Framework.SchemaClass calcParams = EngineData.ReadCalculationParameter(data);

            List <ElementId> listCombinationId = new List <ElementId>();

            if (server.LoadCasesAndCombinationsSupport())
            {
                listCombinationId = storageDocument.CalculationParamsManager.CalculationParams.GetLoadCasesAndCombinations(Server.Server.ID);
            }

            CommonParametersBase parameBase = new CommonParametersBase(listElementStatus, listCombinationId, activePackageId, calcParams);
            CommonParametersBase parameters = EngineData.CreateCommonParameters(data, parameBase);

            return(parameters);
        }
Пример #4
0
        /// <summary>
        /// Reads from Revit information about selected elements and store it in the list with elements data.
        /// </summary>
        /// <param name="data">Acces to cref="ServiceData".</param>
        /// <param name="listElementStatus">List identyficators of elements with result status.</param>
        /// <param name="parameters">Common parameters.</param>
        /// <returns>List of elements data.</returns>
        protected List <ObjectDataBase> ReadListElementData(Autodesk.Revit.DB.CodeChecking.ServiceData data, List <Tuple <ElementId, ResultStatus> > listElementStatus, CommonParametersBase parameters)
        {
            Autodesk.Revit.DB.CodeChecking.Storage.StorageService  service         = Autodesk.Revit.DB.CodeChecking.Storage.StorageService.GetStorageService();
            Autodesk.Revit.DB.CodeChecking.Storage.StorageDocument storageDocument = service.GetStorageDocument(data.Document);

            List <ObjectDataBase> listElementData = new List <ObjectDataBase>();

            foreach (Tuple <ElementId, ResultStatus> elemStatus in listElementStatus)
            {
                Element element = data.Document.GetElement(elemStatus.Item1);
                if (element != null)
                {
                    Autodesk.Revit.DB.CodeChecking.Storage.Label ccLabel = storageDocument.LabelsManager.GetLabel(element);
                    if (ccLabel != null)
                    {
                        Autodesk.Revit.DB.BuiltInCategory category = (Autodesk.Revit.DB.BuiltInCategory)element.Category.Id.IntegerValue;
                        StructuralAssetClass material = ccLabel.Material;
                        Autodesk.Revit.DB.ExtensibleStorage.Framework.SchemaClass label  = EngineData.ReadElementLabel(category, material, ccLabel, data);
                        Autodesk.Revit.DB.ExtensibleStorage.Framework.SchemaClass result = EngineData.CreateElementResult(category, material);

                        ObjectDataBase         objectData       = new ObjectDataBase(elemStatus.Item1, category, material, label);
                        List <SectionDataBase> listSectionsData = new List <SectionDataBase>();
                        List <CalcPoint>       listCalcPoints   = EngineData.CreateCalcPointsForElement(data, parameters, elemStatus.Item1);
                        foreach (CalcPoint p in listCalcPoints)
                        {
                            SectionDataBase sectBase = new SectionDataBase(p, objectData);
                            SectionDataBase sectData = EngineData.CreateSectionData(sectBase);

                            listSectionsData.Add(sectData);
                        }

                        ElementDataBase elemBase = new ElementDataBase(result, listCalcPoints, listSectionsData, elemStatus.Item2, data.Document, objectData);
                        ElementDataBase elemData = EngineData.CreateElementData(elemBase);

                        listElementData.Add(elemData);
                    }
                }
            }

            return(listElementData);
        }
Пример #5
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();
                            }
                        });
                    }
                }
            }
        }