MCPcopy Create free account
hub / github.com/IfcOpenShell/IfcOpenShell / getUnit

Method getUnit

src/ifcparse/IfcParse.cpp:2686–2751  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2684}
2685
2686std::pair<IfcUtil::IfcBaseClass*, double> IfcFile::getUnit(const std::string& unit_type) {
2687 std::pair<IfcUtil::IfcBaseClass*, double> return_value(0, 1.);
2688
2689 aggregate_of_instance::ptr projects = instances_by_type(schema()->declaration_by_name("IfcProject"));
2690 if (!projects || projects->size() == 0) {
2691 try {
2692 projects = instances_by_type(schema()->declaration_by_name("IfcContext"));
2693 } catch (IfcException&) {
2694 }
2695 }
2696
2697 if (projects && projects->size() == 1) {
2698 IfcUtil::IfcBaseClass* project = *projects->begin();
2699
2700 IfcUtil::IfcBaseClass* unit_assignment = project->get_attribute_value(
2701 project->declaration().as_entity()->attribute_index("UnitsInContext"));
2702
2703 aggregate_of_instance::ptr units = unit_assignment->get_attribute_value(
2704 unit_assignment->declaration().as_entity()->attribute_index("Units"));
2705
2706 for (aggregate_of_instance::it it = units->begin(); it != units->end(); ++it) {
2707 IfcUtil::IfcBaseClass* unit = *it;
2708 if (unit->declaration().is("IfcNamedUnit")) {
2709 const std::string file_unit_type = unit->get_attribute_value(
2710 unit->declaration().as_entity()->attribute_index("UnitType"));
2711
2712 if (file_unit_type != unit_type) {
2713 continue;
2714 }
2715
2716 IfcUtil::IfcBaseClass* siunit = 0;
2717 if (unit->declaration().is("IfcConversionBasedUnit")) {
2718 IfcUtil::IfcBaseClass* mu = unit->get_attribute_value(
2719 unit->declaration().as_entity()->attribute_index("ConversionFactor"));
2720
2721 IfcUtil::IfcBaseClass* vlc = mu->get_attribute_value(
2722 mu->declaration().as_entity()->attribute_index("ValueComponent"));
2723
2724 IfcUtil::IfcBaseClass* unc = mu->get_attribute_value(
2725 mu->declaration().as_entity()->attribute_index("UnitComponent"));
2726
2727 return_value.second *= static_cast<double>(vlc->get_attribute_value(0));
2728 return_value.first = unit;
2729
2730 if (unc->declaration().is("IfcSIUnit")) {
2731 siunit = unc;
2732 }
2733
2734 } else if (unit->declaration().is("IfcSIUnit")) {
2735 return_value.first = siunit = unit;
2736 }
2737
2738 if (siunit != nullptr) {
2739 AttributeValue prefix = siunit->get_attribute_value(
2740 siunit->declaration().as_entity()->attribute_index("Prefix"));
2741
2742 if (!prefix.isNull()) {
2743 return_value.second *= IfcSIPrefixToValue(prefix);

Callers 4

writeMethod · 0.80
finalizeMethod · 0.80
addEntityMethod · 0.80

Calls 8

instances_by_typeFunction · 0.85
get_attribute_valueMethod · 0.80
isMethod · 0.80
isNullMethod · 0.80
schemaFunction · 0.70
sizeMethod · 0.45
beginMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected