Skip to content

Commit

Permalink
David/cnx 930 create a getelementproperties converter (#7)
Browse files Browse the repository at this point in the history
* sending properties

* GetElementMaterialQuantities

* ArchicadObject

* GetElementClassifications

* cherry pick element properties by guid

* added element type quantity getters

* getting more quantities

* RootObjectBuilder refactor

* opacity bugfix

* opacity bugfix

* removed duplicate properties

* user defined props under groups

* do not return null prop values

* wall quantities restructure

* working units, override material names and surfaces

* workingunits fix

* GetElementProperties refactor, moved all property collection logic to converter from RootObjectBuilder

* do not send empty dictionaries
  • Loading branch information
kekesidavid authored Jan 16, 2025
1 parent 36fc9cf commit f490ec8
Show file tree
Hide file tree
Showing 17 changed files with 962 additions and 69 deletions.
56 changes: 27 additions & 29 deletions AddOns/Speckle/Sources/AddOn/Connector/RootObjectBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,41 @@ RootObject RootObjectBuilder::GetRootObject(const std::vector<std::string>& elem
for (const auto& elemId : elementIds)
{
SendConversionResult conversionResult{};

ElementBody body{};
std::string levelName;
std::string elementType;
ArchicadObject archicadObject;

try
{
elementType = CONNECTOR.GetHostToSpeckleConverter().GetElementType(elemId);
conversionResult.sourceType = elementType;
archicadObject.applicationId = elemId;
archicadObject.name = CONNECTOR.GetHostToSpeckleConverter().GetElementName(elemId);
archicadObject.type = CONNECTOR.GetHostToSpeckleConverter().GetElementType(elemId);
conversionResult.sourceType = archicadObject.type;
conversionResult.sourceId = elemId;
body = CONNECTOR.GetHostToSpeckleConverter().GetElementBody(elemId);
bodies.push_back(body);
archicadObject.displayValue = body;
conversionResult.resultId = "";
conversionResult.resultType = "Mesh";
levelName = CONNECTOR.GetHostToSpeckleConverter().GetElementLevel(elemId);
archicadObject.level = CONNECTOR.GetHostToSpeckleConverter().GetElementLevel(elemId);
archicadObject.properties = CONNECTOR.GetHostToSpeckleConverter().GetElementProperties(elemId);

if (rootObject.elements.find(archicadObject.level) == rootObject.elements.end())
{
Level level{};
level.name = archicadObject.level;
rootObject.elements[archicadObject.level] = level;
}

Level& level = rootObject.elements[archicadObject.level];
if (level.elements.find(archicadObject.type) == level.elements.end())
{
ElementTypeCollection collection{};
collection.name = archicadObject.type;
level.elements[archicadObject.type] = collection;
}

ElementTypeCollection& elementTypeCollection = level.elements[archicadObject.type];
elementTypeCollection.elements.push_back(archicadObject);
}
catch (const ArchiCadApiException& ae)
{
Expand All @@ -38,29 +59,6 @@ RootObject RootObjectBuilder::GetRootObject(const std::vector<std::string>& elem
conversionResult.error.message = se.what();
}

bodies.push_back(body);
ModelElement modelElement;
modelElement.applicationId = elemId;
modelElement.displayValue = body;

if (rootObject.elements.find(levelName) == rootObject.elements.end())
{
Level level{};
level.name = levelName;
rootObject.elements[levelName] = level;
}

Level& level = rootObject.elements[levelName];
if (level.elements.find(elementType) == level.elements.end())
{
ElementTypeCollection collection{};
collection.name = elementType;
level.elements[elementType] = collection;
}

ElementTypeCollection& elementTypeCollection = level.elements[elementType];
elementTypeCollection.elements.push_back(modelElement);

conversionResults.push_back(conversionResult);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#include "HostToSpeckleConverter.h"
#include "ConverterUtils.h"

#include "APIEnvir.h"
#include "ACAPinc.h"
#include "CheckError.h"

namespace
{
std::string GetClassifictaionName(const API_Guid& classificationId)
{
API_ClassificationItem classification{};
classification.guid = classificationId;
ACAPI_Classification_GetClassificationItem(classification);
std::string classificationName = classification.id.ToCStr().Get();

return classificationName;
}

std::string GetClassifictaionSystemName(const API_Guid& classificationSystemId)
{
API_ClassificationSystem system{};
system.guid = classificationSystemId;
ACAPI_Classification_GetClassificationSystem(system);
std::string systemName = system.name.ToCStr().Get();
std::string systemEdition = system.editionVersion.ToCStr().Get();

return systemName + " - " + systemEdition;
}
}

std::map<std::string, std::string> HostToSpeckleConverter::GetElementClassifications(const std::string& elemId)
{
std::map<std::string, std::string> classifications;

auto apiGuid = APIGuidFromString(elemId.c_str());

GS::Array<GS::Pair<API_Guid, API_Guid>> classificationItems;
ACAPI_Element_GetClassificationItems(apiGuid, classificationItems);

for (const auto& item : classificationItems)
{
auto classificationSystemName = GetClassifictaionSystemName(item.first);
auto classificationName = GetClassifictaionName(item.second);
classifications[classificationSystemName] = classificationName;
}

return classifications;
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ namespace
std::string HostToSpeckleConverter::GetElementLevel(const std::string& elemId)
{
std::string floorName = "";
auto apielem = ConverterUtils::GetElement(elemId);
auto floorInd = apielem.header.floorInd;
auto apiElem = ConverterUtils::GetElement(elemId);
auto floorInd = apiElem.header.floorInd;

API_StoryInfo storyInfo{};
CHECK_ERROR(ACAPI_ProjectSetting_GetStorySettings(&storyInfo));
Expand Down
Loading

0 comments on commit f490ec8

Please sign in to comment.