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

Method set_default_style_file

src/ifcgeom/SurfaceStyle.cpp:76–113  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

74}
75
76void IfcGeom::set_default_style_file(const std::string& json_file) {
77 if (!default_materials_initialized) InitDefaultMaterials();
78 default_materials.clear();
79
80 // @todo this will probably need to be updated for UTF-8 paths on Windows
81 pt::ptree root;
82 pt::read_json(json_file, root);
83
84 for (pt::ptree::value_type &material_pair : root) {
85 std::string name = material_pair.first;
86 default_materials.insert(std::make_pair(name, std::make_shared<ifcopenshell::geometry::taxonomy::style>(name)));
87
88 pt::ptree material = material_pair.second;
89 boost::optional<pt::ptree&> diffuse = material.get_child_optional("diffuse");
90 default_materials[name]->diffuse = read_colour_component(diffuse);
91
92 // @todo Is it necessary to get the surface too?
93 // boost::optional<pt::ptree&> surface = material.get_child_optional("surface");
94 // default_materials[name]->surface = read_colour_component(surface);
95
96 boost::optional<pt::ptree&> specular = material.get_child_optional("specular");
97 default_materials[name]->specular = read_colour_component(specular);
98
99 if (material.get_child_optional("specular-roughness")) {
100 default_materials[name]->specularity = 1.0 / material.get<double>("specular-roughness");
101 }
102 if (material.get_child_optional("transparency")) {
103 default_materials[name]->transparency = material.get<double>("transparency");
104 }
105 }
106
107 // Is "*" present? If yes, remove it and make it the default style.
108 auto it = default_materials.find("*");
109 if (it != default_materials.end()) {
110 default_material = it->second;
111 default_materials.erase(it);
112 }
113}
114
115const ifcopenshell::geometry::taxonomy::style::ptr& IfcGeom::get_default_style(const std::string& s) {
116 static std::mutex m;

Callers

nothing calls this directly

Calls 7

InitDefaultMaterialsFunction · 0.85
read_colour_componentFunction · 0.85
clearMethod · 0.45
insertMethod · 0.45
findMethod · 0.45
endMethod · 0.45
eraseMethod · 0.45

Tested by

no test coverage detected