added Revit 2022 SDK minus except *rvt and *rfa

This commit is contained in:
Jeremy Tammik
2021-04-20 11:36:21 +02:00
parent 1133a82dc5
commit 7e327986e8
3034 changed files with 1245318 additions and 0 deletions
@@ -0,0 +1,107 @@
//
// (C) Copyright 2003-2013 by Autodesk, Inc.
//
// Permission to use, copy, modify, and distribute this software in
// object code form for any purpose and without fee is hereby granted,
// provided that the above copyright notice appears in all copies and
// that both that copyright notice and the limited warranty and
// restricted rights notice below appear in all supporting
// documentation.
//
// AUTODESK PROVIDES THIS PROGRAM "AS IS" AND WITH ALL FAULTS.
// AUTODESK SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTY OF
// MERCHANTABILITY OR FITNESS FOR A PARTICULAR USE. AUTODESK, INC.
// DOES NOT WARRANT THAT THE OPERATION OF THE PROGRAM WILL BE
// UNINTERRUPTED OR ERROR FREE.
//
// Use, duplication, or disclosure by the U.S. Government is subject to
// restrictions set forth in FAR 52.227-19 (Commercial Computer
// Software - Restricted Rights) and DFAR 252.227-7013(c)(1)(ii)
// (Rights in Technical Data and Computer Software), as applicable.
//
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Autodesk.Revit.DB;
using Autodesk.Revit.DB.CodeChecking.Engineering;
using Autodesk.Revit.DB.CodeChecking.Storage;
namespace CodeCheckingConcreteExample.Engine
{
/// <summary>
/// Represents common parameters.
/// </summary>
public class CommonParametersBase
{
/// <summary>
/// Initializes a new instance of the CommonParametersBase object with list of parameters.
/// </summary>
/// <param name="listElementStatus">List identyficators of elements with result status.</param>
/// <param name="listCombinationId">List load combinations identificators</param>
/// <param name="activePackageGuid">Identificator of active package with results.</param>
/// <param name="calculationParameters">Calculation parameters.</param>
public CommonParametersBase(List<Tuple<ElementId, ResultStatus>> listElementStatus,
List<ElementId> listCombinationId,
Guid activePackageGuid,
Autodesk.Revit.DB.ExtensibleStorage.Framework.SchemaClass calculationParameters)
{
listElemStatus = listElementStatus;
listCombId = listCombinationId;
this.activePackageGuid = activePackageGuid;
calcParams = calculationParameters;
}
/// <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;
}
private CommonParametersBase() { }
/// <summary>
/// Gets the list of elements identificators.
/// </summary>
public List<Tuple<ElementId, ResultStatus>> ListElementStatus
{
get { return listElemStatus; }
}
/// <summary>
/// Gets the list of load combinations identificators.
/// </summary>
public List<ElementId> ListCombinationId
{
get { return listCombId; }
}
/// <summary>
/// Gets the calculation parameters.
/// </summary>
public Autodesk.Revit.DB.ExtensibleStorage.Framework.SchemaClass CalculationParameter
{
get { return calcParams; }
}
/// <summary>
/// Gets the identificator of an active package with results.
/// </summary>
public Guid ActivePackageGuid
{
get { return activePackageGuid; }
}
private Guid activePackageGuid;
private List<Tuple<ElementId, ResultStatus>> listElemStatus;
private List<ElementId> listCombId;
private Autodesk.Revit.DB.ExtensibleStorage.Framework.SchemaClass calcParams;
}
}
@@ -0,0 +1,142 @@
//
// (C) Copyright 2003-2013 by Autodesk, Inc.
//
// Permission to use, copy, modify, and distribute this software in
// object code form for any purpose and without fee is hereby granted,
// provided that the above copyright notice appears in all copies and
// that both that copyright notice and the limited warranty and
// restricted rights notice below appear in all supporting
// documentation.
//
// AUTODESK PROVIDES THIS PROGRAM "AS IS" AND WITH ALL FAULTS.
// AUTODESK SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTY OF
// MERCHANTABILITY OR FITNESS FOR A PARTICULAR USE. AUTODESK, INC.
// DOES NOT WARRANT THAT THE OPERATION OF THE PROGRAM WILL BE
// UNINTERRUPTED OR ERROR FREE.
//
// Use, duplication, or disclosure by the U.S. Government is subject to
// restrictions set forth in FAR 52.227-19 (Commercial Computer
// Software - Restricted Rights) and DFAR 252.227-7013(c)(1)(ii)
// (Rights in Technical Data and Computer Software), as applicable.
//
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Autodesk.Revit.DB;
using Autodesk.Revit.DB.CodeChecking.Engineering;
using Autodesk.Revit.DB.CodeChecking.Storage;
namespace CodeCheckingConcreteExample.Engine
{
/// <summary>
/// Represents a base of element data.
/// </summary>
public class ElementDataBase : ObjectDataBase
{
/// <summary>
/// Initializes a new instance of the ElementDataBase object with list of parameters.
/// </summary>
/// <param name="elementResult">Element results schema.</param>
/// <param name="listcalcPoint">List of the element's calculation points.</param>
/// <param name="listSectionData">List of sections' data.</param>
/// <param name="elementStatus">Element result status.</param>
/// <param name="document">Acces to cref="Document".</param>
/// <param name="data">Object with base parameters for the element.</param>
public ElementDataBase(Autodesk.Revit.DB.ExtensibleStorage.Framework.SchemaClass elementResult,
List<CalcPoint> listcalcPoint,
List<SectionDataBase> listSectionData,
Autodesk.Revit.DB.CodeChecking.Storage.ResultStatus elementStatus,
Document document,
ObjectDataBase data)
: base(data)
{
Result = elementResult;
calcPoints = listcalcPoint;
listSectData = listSectionData;
Status = elementStatus;
this.document = document;
}
/// <summary>
/// Initializes a new instance of the ElementDataBase from an existing one.
/// </summary>
/// <param name="elementDataBase">Element data to copy.</param>
public ElementDataBase(ElementDataBase elementDataBase)
: base(elementDataBase as ObjectDataBase)
{
Result = elementDataBase.Result;
calcPoints = elementDataBase.ListCalcPoints;
listSectData = elementDataBase.ListSectionData;
Status = elementDataBase.Status;
document = elementDataBase.document;
}
private ElementDataBase() { }
/// <summary>
/// Result schema of the element.
/// </summary>
public Autodesk.Revit.DB.ExtensibleStorage.Framework.SchemaClass Result { get; set; }
/// <summary>
/// List of calculation points cref="CalcPoint" of the element.
/// </summary>
public List<CalcPoint> ListCalcPoints
{
get { return calcPoints; }
}
/// <summary>
/// List of sections data of the element.
/// </summary>
public List<SectionDataBase> ListSectionData
{
get { return listSectData; }
}
/// <summary>
/// Gets and sets the element's result status.
/// </summary>
public Autodesk.Revit.DB.CodeChecking.Storage.ResultStatus Status { get; set; }
/// <summary>
/// Adds the formated error to cref="Status".
/// </summary>
/// <param name="message">The message.</param>
/// <param name="notify">if set to <c>true</c> [notify].</param>
public void AddFormatedError(ResultStatusMessage message, bool notify = true)
{
Status.AddError(message, document, notify);
}
/// <summary>
/// Adds the formated info to cref="Status".
/// </summary>
/// <param name="message">The message.</param>
/// <param name="notify">if set to <c>true</c> [notify].</param>
public void AddFormatedInfo(ResultStatusMessage message, bool notify = true)
{
Status.AddInfo(message, document, notify);
}
/// <summary>
/// Adds the formated warning to cref="Status".
/// </summary>
/// <param name="message">The message.</param>
/// <param name="notify">if set to <c>true</c> [notify].</param>
public void AddFormatedWarning(ResultStatusMessage message, bool notify = true)
{
Status.AddWarning(message, document, notify);
}
List<CalcPoint> calcPoints;
private List<SectionDataBase> listSectData;
/// <summary>
/// Revit document
/// </summary>
protected Document document;
}
}
@@ -0,0 +1,444 @@
//
// (C) Copyright 2003-2013 by Autodesk, Inc.
//
// Permission to use, copy, modify, and distribute this software in
// object code form for any purpose and without fee is hereby granted,
// provided that the above copyright notice appears in all copies and
// that both that copyright notice and the limited warranty and
// restricted rights notice below appear in all supporting
// documentation.
//
// AUTODESK PROVIDES THIS PROGRAM "AS IS" AND WITH ALL FAULTS.
// AUTODESK SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTY OF
// MERCHANTABILITY OR FITNESS FOR A PARTICULAR USE. AUTODESK, INC.
// DOES NOT WARRANT THAT THE OPERATION OF THE PROGRAM WILL BE
// UNINTERRUPTED OR ERROR FREE.
//
// Use, duplication, or disclosure by the U.S. Government is subject to
// restrictions set forth in FAR 52.227-19 (Commercial Computer
// Software - Restricted Rights) and DFAR 252.227-7013(c)(1)(ii)
// (Rights in Technical Data and Computer Software), as applicable.
//
using System;
using System.Collections.Generic;
using Autodesk.Revit.DB.CodeChecking;
using Autodesk.Revit.DB.CodeChecking.Documentation;
using Autodesk.Revit.DB.CodeChecking.Engineering;
using Autodesk.Revit.DB;
using Autodesk.Revit.DB.ExtensibleStorage.Framework;
using Autodesk.Revit.DB.CodeChecking.Storage;
using CodeCheckingConcreteExample.Server;
using CodeCheckingConcreteExample.Properties;
using System.Threading;
using System.Threading.Tasks;
namespace CodeCheckingConcreteExample.Engine
{
/// <summary>
/// Represents the main calculation loop.
/// </summary>
public class Engine
{
private IEngineData EngineData;
private Engine() { }
/// <summary>
/// Initializes a new instance of the Engine class.
/// </summary>
/// <param name="engineData">The interface cref="IEngineData" needed to parametrize Engine.</param>
public Engine(IEngineData engineData)
{
EngineData = engineData;
}
/// <summary>
/// Runs calculation for elements served in user implementation of cref="IEngineData".
/// </summary>
/// <param name="server">Acces to cref="Server".</param>
/// <param name="data">Acces to cref="ServiceData".</param>
public void Calculate(Server.Server server, Autodesk.Revit.DB.CodeChecking.ServiceData data)
{
List<Tuple<ElementId, ResultStatus>> listElementStatus = ReadListElementIdWithStatus(server, data);
if (listElementStatus.Count > 0)
CalculateSetOfElements(listElementStatus, server, data);
}
/// <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);
}
}
/// <structural_toolkit_2015>
/// <summary>
/// Gets list of elements with the given category.
/// </summary>
/// <param name="category">Category of the element.</param>
/// <param name="material">Material of the element.</param>
/// <param name="listElementData">List of elements objects</param>
List<ObjectDataBase> GetListElementForCategory(BuiltInCategory category, StructuralAssetClass material, List<ObjectDataBase> listElementData)
{
List<ObjectDataBase> list = new List<ObjectDataBase>();
foreach (ObjectDataBase obj in listElementData)
if (obj.Category == category && obj.Material == material)
list.Add(obj);
return list;
}
/// </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();
});
}
}
}
/// </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;
}
/// <summary>
/// Reads from Revit selected elements identificators and collect in the list only that which has apprppriate label, material and category.
/// </summary>
/// <param name="server">Acces to cref="Server".</param>
/// <param name="data">Acces to cref="ServiceData".</param>
/// <returns>List identyficators of elements with result status.</returns>
protected List<Tuple<ElementId, ResultStatus>> ReadListElementIdWithStatus(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());
List<Tuple<ElementId, ResultStatus>> listElementId = new List<Tuple<ElementId, ResultStatus>>();
foreach (Element element in data.Selection)
{
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;
if (server.GetSupportedMaterials().Contains(material) &&
server.GetSupportedCategories(material).Contains(category))
{
ElementId id = new ElementId(element.Id.IntegerValue);
SchemaClass label = EngineData.ReadElementLabel(category, material, ccLabel, data);
ResultStatus status = new Autodesk.Revit.DB.CodeChecking.Storage.ResultStatus(Server.Server.ID, activePackageId);
EngineData.VerifyElementLabel(category, material, label, ref status);
listElementId.Add(new Tuple<ElementId, ResultStatus>(id, status));
}
}
}
return listElementId;
}
/// <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;
}
/// <summary>
/// Saves in Revit data base information collected in the list elements data.
/// </summary>
/// <param name="data">Acces to cref="ServiceData".</param>
/// <param name="listElementData">List of elements data.</param>
protected void SaveListElementData(Autodesk.Revit.DB.CodeChecking.ServiceData data, List<ObjectDataBase> listElementData)
{
Autodesk.Revit.DB.CodeChecking.NotificationService.ProgressStart(Resources.ResourceManager.GetString("DataSaving"), listElementData.Count);
int step = 0;
foreach (ElementDataBase elemData in listElementData)
{
SaveElementResult(elemData.ElementId, elemData.Result, elemData.Status, data);
step++;
Autodesk.Revit.DB.CodeChecking.NotificationService.ProgressStep(string.Format("{0:d}%", step * 100 / listElementData.Count));
}
}
/// <summary>
/// Saves in Revit the result object of an element.
/// </summary>
/// <param name="elementId">Identificator of an element.</param>
/// <param name="resultSchema">Result object.</param>
/// <param name="status">Status of element's results.</param>
/// <param name="data">Acces to cref="ServiceData".</param>
protected void SaveElementResult(ElementId elementId, Autodesk.Revit.DB.ExtensibleStorage.Framework.SchemaClass resultSchema, Autodesk.Revit.DB.CodeChecking.Storage.ResultStatus status, 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);
Element element = data.Document.GetElement(elementId);
if (resultSchema != null)
storageDocument.ResultsManager.SetResult(resultSchema.GetEntity(), element, status, true);
}
}
}
@@ -0,0 +1,88 @@
//
// (C) Copyright 2003-2013 by Autodesk, Inc.
//
// Permission to use, copy, modify, and distribute this software in
// object code form for any purpose and without fee is hereby granted,
// provided that the above copyright notice appears in all copies and
// that both that copyright notice and the limited warranty and
// restricted rights notice below appear in all supporting
// documentation.
//
// AUTODESK PROVIDES THIS PROGRAM "AS IS" AND WITH ALL FAULTS.
// AUTODESK SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTY OF
// MERCHANTABILITY OR FITNESS FOR A PARTICULAR USE. AUTODESK, INC.
// DOES NOT WARRANT THAT THE OPERATION OF THE PROGRAM WILL BE
// UNINTERRUPTED OR ERROR FREE.
//
// Use, duplication, or disclosure by the U.S. Government is subject to
// restrictions set forth in FAR 52.227-19 (Commercial Computer
// Software - Restricted Rights) and DFAR 252.227-7013(c)(1)(ii)
// (Rights in Technical Data and Computer Software), as applicable.
//
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace CodeCheckingConcreteExample.Engine
{
/// <summary>
/// Represents type of a calculation object.
/// </summary>
public enum CalculationObjectType
{
/// <summary>
/// Designed for elements objects.
/// </summary>
Element,
/// <summary>
/// Designed for sections objects.
/// </summary>
Section,
}
/// <summary>
/// Represents type of a calculation object.
/// </summary>
public enum ErrorResponse
{
/// <summary>
/// Execute the Run method when "false" value was returned in previus Run methods.
/// </summary>
RunOnError,
/// <summary>
/// Skip the Run method when "false" value was returned in previus Run methods.
/// </summary>
SkipOnError,
}
/// <summary>
/// Base interface for calculation objects.
/// </summary>
public interface ICalculationObject
{
/// <summary>
/// Runs calculation\operations for an element cref="ElementDataBase" object or for a section object cref="SectionDataBase".
/// </summary>
/// <param name="obj">An element object or a section object</param>
/// <returns>Result of calculation.</returns>
bool Run(ObjectDataBase obj);
/// <summary>
/// Sets and gets common parameters.
/// </summary>
CommonParametersBase Parameters { get; set; }
/// <summary>
/// Gets and sets type of the calculation object.
/// </summary>
CalculationObjectType Type { get; set; }
/// <summary>
/// Gets and sets a type of error response of the calculation object.
/// </summary>
ErrorResponse ErrorResponse { get; set; }
/// <summary>
/// Gets and sets categories for the calculation object.
/// </summary>
IList<Autodesk.Revit.DB.BuiltInCategory> Categories { get; set; }
}
}
@@ -0,0 +1,47 @@
//
// (C) Copyright 2003-2013 by Autodesk, Inc.
//
// Permission to use, copy, modify, and distribute this software in
// object code form for any purpose and without fee is hereby granted,
// provided that the above copyright notice appears in all copies and
// that both that copyright notice and the limited warranty and
// restricted rights notice below appear in all supporting
// documentation.
//
// AUTODESK PROVIDES THIS PROGRAM "AS IS" AND WITH ALL FAULTS.
// AUTODESK SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTY OF
// MERCHANTABILITY OR FITNESS FOR A PARTICULAR USE. AUTODESK, INC.
// DOES NOT WARRANT THAT THE OPERATION OF THE PROGRAM WILL BE
// UNINTERRUPTED OR ERROR FREE.
//
// Use, duplication, or disclosure by the U.S. Government is subject to
// restrictions set forth in FAR 52.227-19 (Commercial Computer
// Software - Restricted Rights) and DFAR 252.227-7013(c)(1)(ii)
// (Rights in Technical Data and Computer Software), as applicable.
//
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace CodeCheckingConcreteExample.Engine
{
/// <summary>
/// Base interface for calculation scenario.
/// </summary>
public interface ICalculationScenario
{
/// <structural_toolkit_2015>
/// <summary>
/// Gets list of calculation objects cref="ICalculationObject".
/// </summary>
/// <param name="category">Category of the element.</param>
/// <param name="material">Material of the element.</param>
/// <returns>List of calculation objects.</returns>
List<ICalculationObject> CalculationScenarioList(Autodesk.Revit.DB.BuiltInCategory category, Autodesk.Revit.DB.StructuralAssetClass material);
/// </structural_toolkit_2015>
}
}
@@ -0,0 +1,137 @@
//
// (C) Copyright 2003-2013 by Autodesk, Inc.
//
// Permission to use, copy, modify, and distribute this software in
// object code form for any purpose and without fee is hereby granted,
// provided that the above copyright notice appears in all copies and
// that both that copyright notice and the limited warranty and
// restricted rights notice below appear in all supporting
// documentation.
//
// AUTODESK PROVIDES THIS PROGRAM "AS IS" AND WITH ALL FAULTS.
// AUTODESK SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTY OF
// MERCHANTABILITY OR FITNESS FOR A PARTICULAR USE. AUTODESK, INC.
// DOES NOT WARRANT THAT THE OPERATION OF THE PROGRAM WILL BE
// UNINTERRUPTED OR ERROR FREE.
//
// Use, duplication, or disclosure by the U.S. Government is subject to
// restrictions set forth in FAR 52.227-19 (Commercial Computer
// Software - Restricted Rights) and DFAR 252.227-7013(c)(1)(ii)
// (Rights in Technical Data and Computer Software), as applicable.
//
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Autodesk.Revit.DB;
using Autodesk.Revit.DB.CodeChecking.Engineering;
namespace CodeCheckingConcreteExample.Engine
{
/// <summary>
/// Base interface for the main loop class. Parameter of the constructor of the cref="Engine" class.
/// </summary>
public interface IEngineData
{
/// <summary>
/// Gets the unit system
/// </summary>
/// <returns>cref="DisplayUnit"</returns>
DisplayUnit GetInputDataUnitSystem();
/// <summary>
/// Gets number of available threads or processors.
/// </summary>
/// <param name="data">Service data.</param>
/// <returns>Number of threads</returns>
int GetNumberOfThreads(Autodesk.Revit.DB.CodeChecking.ServiceData data);
/// <structural_toolkit_2015>
/// <summary>
/// Creates user imlementation of cref="ICalculationScenario" which consists list of calculation objects cref="ICalculatinObject".
/// </summary>
/// <param name="parameters">Instance of base class with common parameters.</param>
/// <returns>The new instance of cref="ICalculationScenario"</returns>
ICalculationScenario CreateCalculationScenario(CommonParametersBase parameters);
/// </structural_toolkit_2015>
/// <summary>
/// Creates new instance of a class with common parameters.
/// </summary>
/// <param name="data">Acces to cref="ServiceData".</param>
/// <param name="parameters">Instance of base class with common parameters.</param>
/// <returns>New instance of user implementation of class derived from cref="CommonParametersBase".</returns>
CommonParametersBase CreateCommonParameters(Autodesk.Revit.DB.CodeChecking.ServiceData data, CommonParametersBase parameters);
/// <summary>
/// Creates new instance of class with list of calculation points.
/// </summary>
/// <param name="data">Acces to cref="ServiceData".</param>
/// <param name="parameters">User object with common parameters.</param>
/// <param name="elementId">Id of an element.</param>
/// <returns>List of calculation points.</returns>
List<CalcPoint> CreateCalcPointsForElement(Autodesk.Revit.DB.CodeChecking.ServiceData data, CommonParametersBase parameters, ElementId elementId);
/// <summary>
/// Creates new instance of user class which represents a section of a structure element.
/// </summary>
/// <param name="sectionDataBase">Instance of base class for the section.</param>
/// <returns>New instance of user implementation of section class derived from cref="SectionDataBase".</returns>
SectionDataBase CreateSectionData(SectionDataBase sectionDataBase);
/// <summary>
/// Creates new instance of user class which represents a structure element.
/// </summary>
/// <param name="elementDataBase">Instance of base class for the element.</param>
/// <returns>New instance of user implementation of element class derived from cref="ElementDataBase".</returns>
ElementDataBase CreateElementData(ElementDataBase elementDataBase);
/// <summary>
/// Creates new instance of class with results for the element.
/// </summary>
/// <param name="category">Category of the element.</param>
/// <param name="material">Material of the element.</param>
/// <returns>User result schema object for the element.</returns>
Autodesk.Revit.DB.ExtensibleStorage.Framework.SchemaClass CreateElementResult(Autodesk.Revit.DB.BuiltInCategory category, StructuralAssetClass material);
/// <summary>
/// Reads calculation parameters from revit data base.
/// </summary>
/// <param name="data">Acces to cref="ServiceData".</param>
/// <returns>User calculation parameters schema object.</returns>
Autodesk.Revit.DB.ExtensibleStorage.Framework.SchemaClass ReadCalculationParameter(Autodesk.Revit.DB.CodeChecking.ServiceData data);
/// <summary>
/// Reads parameters of user element label.
/// </summary>
/// <param name="category">Category of the element.</param>
/// <param name="material">Material of the element.</param>
/// <param name="label">Acces to the Revit storage with labels."</param>
/// <param name="data">Acces to cref="ServiceData".</param>
/// <returns>User label of the element.</returns>
Autodesk.Revit.DB.ExtensibleStorage.Framework.SchemaClass ReadElementLabel(Autodesk.Revit.DB.BuiltInCategory category, StructuralAssetClass material, Autodesk.Revit.DB.CodeChecking.Storage.Label label, Autodesk.Revit.DB.CodeChecking.ServiceData data);
/// <summary>
/// Verify parameters of user element label.
/// </summary>
/// <param name="category">Category of the element.</param>
/// <param name="material">Material of the element.</param>
/// <param name="label">Element label."</param>
/// <param name="status">Reference to element's status".</param>
void VerifyElementLabel(Autodesk.Revit.DB.BuiltInCategory category, StructuralAssetClass material, Autodesk.Revit.DB.ExtensibleStorage.Framework.SchemaClass label, ref Autodesk.Revit.DB.CodeChecking.Storage.ResultStatus status);
/// <summary>
/// Filters list of elements due to e.g. a result status for calculation purposes.
/// </summary>
/// <param name="listElementData">List of user element objects.</param>
/// <returns>Filtered list of user element objects.</returns>
List<ObjectDataBase> FilterElementForCalculation(List<ObjectDataBase> listElementData);
/// <summary>
/// Gives possibility to read data from Revit data base and puts them into user element's objects and into user section's objects and into user common parameters.
/// </summary>
/// <param name="listElementData">List of user element objects.</param>
/// <param name="parameters">User common parameters.</param>
/// <param name="data">Acces to cref="ServiceData".</param>
void ReadFromRevitDB(List<ObjectDataBase> listElementData, CommonParametersBase parameters, Autodesk.Revit.DB.CodeChecking.ServiceData data);
/// <summary>
/// Gives possibility to write data to Revit data base.
/// </summary>
/// <param name="listElementData">List of user element objects.</param>
/// <param name="parameters">User common parameters.</param>
/// <param name="data">Acces to cref="ServiceData".</param>
void SaveToRevitDB(List<ObjectDataBase> listElementData, CommonParametersBase parameters, Autodesk.Revit.DB.CodeChecking.ServiceData data);
}
}
@@ -0,0 +1,109 @@
//
// (C) Copyright 2003-2013 by Autodesk, Inc.
//
// Permission to use, copy, modify, and distribute this software in
// object code form for any purpose and without fee is hereby granted,
// provided that the above copyright notice appears in all copies and
// that both that copyright notice and the limited warranty and
// restricted rights notice below appear in all supporting
// documentation.
//
// AUTODESK PROVIDES THIS PROGRAM "AS IS" AND WITH ALL FAULTS.
// AUTODESK SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTY OF
// MERCHANTABILITY OR FITNESS FOR A PARTICULAR USE. AUTODESK, INC.
// DOES NOT WARRANT THAT THE OPERATION OF THE PROGRAM WILL BE
// UNINTERRUPTED OR ERROR FREE.
//
// Use, duplication, or disclosure by the U.S. Government is subject to
// restrictions set forth in FAR 52.227-19 (Commercial Computer
// Software - Restricted Rights) and DFAR 252.227-7013(c)(1)(ii)
// (Rights in Technical Data and Computer Software), as applicable.
//
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Autodesk.Revit.DB;
using Autodesk.Revit.DB.CodeChecking.Engineering;
namespace CodeCheckingConcreteExample.Engine
{
/// <summary>
/// Represents a base of cref"ElementDataBase" or cref="SectionDataBase".
/// </summary>
public class ObjectDataBase
{
/// <summary>
/// Initializes a new instance of the ObjectDataBase object with list of parameters.
/// </summary>
/// <param name="elementId">Element identificator.</param>
/// <param name="elementCategory">Element category.</param>
/// <param name="elementMaterial">Element material.</param>
/// <param name="elementLabel">Element label.</param>
public ObjectDataBase(ElementId elementId,
Autodesk.Revit.DB.BuiltInCategory elementCategory,
StructuralAssetClass elementMaterial,
Autodesk.Revit.DB.ExtensibleStorage.Framework.SchemaClass elementLabel)
{
category = elementCategory;
material = elementMaterial;
elemId = new ElementId(elementId.IntegerValue); ;
label = elementLabel;
}
/// <summary>
/// Initializes a new instance of the ObjectDataBase from an existing one.
/// </summary>
/// <param name="data">Object data to copy</param>
public ObjectDataBase(ObjectDataBase data)
{
category = data.Category;
material = data.Material;
elemId = data.ElementId;
label = data.Label;
}
/// <summary>
/// Initializes a new instance of the ObjectDataBase.
/// </summary>
public ObjectDataBase() { }
/// <summary>
/// Gets the element's category.
/// </summary>
public Autodesk.Revit.DB.BuiltInCategory Category
{
get { return category; }
}
/// <summary>
/// Gets the element's material.
/// </summary>
public StructuralAssetClass Material
{
get { return material; }
}
/// <summary>
/// Gets the element's identificator.
/// </summary>
public ElementId ElementId
{
get { return elemId; }
}
/// <summary>
/// Gets the element's label schema.
/// </summary>
public Autodesk.Revit.DB.ExtensibleStorage.Framework.SchemaClass Label
{
get { return label; }
}
private Autodesk.Revit.DB.BuiltInCategory category;
private StructuralAssetClass material;
private ElementId elemId;
private Autodesk.Revit.DB.ExtensibleStorage.Framework.SchemaClass label;
}
}
@@ -0,0 +1,70 @@
//
// (C) Copyright 2003-2013 by Autodesk, Inc.
//
// Permission to use, copy, modify, and distribute this software in
// object code form for any purpose and without fee is hereby granted,
// provided that the above copyright notice appears in all copies and
// that both that copyright notice and the limited warranty and
// restricted rights notice below appear in all supporting
// documentation.
//
// AUTODESK PROVIDES THIS PROGRAM "AS IS" AND WITH ALL FAULTS.
// AUTODESK SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTY OF
// MERCHANTABILITY OR FITNESS FOR A PARTICULAR USE. AUTODESK, INC.
// DOES NOT WARRANT THAT THE OPERATION OF THE PROGRAM WILL BE
// UNINTERRUPTED OR ERROR FREE.
//
// Use, duplication, or disclosure by the U.S. Government is subject to
// restrictions set forth in FAR 52.227-19 (Commercial Computer
// Software - Restricted Rights) and DFAR 252.227-7013(c)(1)(ii)
// (Rights in Technical Data and Computer Software), as applicable.
//
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Autodesk.Revit.DB;
using Autodesk.Revit.DB.CodeChecking.Engineering;
namespace CodeCheckingConcreteExample.Engine
{
/// <summary>
/// Represents a base of section data.
/// </summary>
public class SectionDataBase : ObjectDataBase
{
/// <summary>
/// Initializes a new instance of the SectionDataBase object with list of parameters.
/// </summary>
/// <param name="point">Calculation point.</param>
/// <param name="data">Object with base parameters for the section.</param>
public SectionDataBase(CalcPoint point, ObjectDataBase data)
: base(data)
{
calcPoint = point;
}
/// <summary>
/// Initializes a new instance of the SectionDataBase from an existing one.
/// </summary>
/// <param name="sectionDataBase">Section data to copy.</param>
public SectionDataBase(SectionDataBase sectionDataBase)
: base(sectionDataBase as ObjectDataBase)
{
calcPoint = sectionDataBase.CalcPoint;
}
private SectionDataBase() { }
/// <summary>
/// Gets a calculation point cref="CalcPoint".
/// </summary>
public CalcPoint CalcPoint
{
get { return calcPoint; }
}
private CalcPoint calcPoint;
}
}